Hello,
I'm developping an app in which we enable a 3Dmodel depending on the string value of the Vumark. My Logic is to create two seperate scripts :
- The first one "VumarkCheck" is to detect the new vumark and extract its string value.
public class VumarkCheck : MonoBehaviour {
private VuMarkManager mVuMarkManager; public Model3DScript model3DScript;
public GameObject[] Model3D = new GameObject[2]; //3d model of AR
void Start() { model3DScript = new Model3DScript(); // register callbacks to VuMark Manager mVuMarkManager = TrackerManager.Instance.GetStateManager().GetVuMarkManager(); mVuMarkManager.RegisterVuMarkDetectedCallback(OnVuMarkDetected); mVuMarkManager.RegisterVuMarkLostCallback(OnVuMarkLost); }
void OnDestroy() { // unregister callbacks from VuMark Manager mVuMarkManager.UnregisterVuMarkDetectedCallback(OnVuMarkDetected); mVuMarkManager.UnregisterVuMarkLostCallback(OnVuMarkLost); }
public void OnVuMarkDetected(VuMarkTarget target) { string vumarkString = GetVuMarkString(target); Debug.Log("New VuMark: " + GetVuMarkString(target)); model3DScript.Show3Dmodel(vumarkString);
}
public void OnVuMarkLost(VuMarkTarget target) { Debug.Log("Lost VuMark: " + GetVuMarkString(target)); }
private string GetVuMarkString(VuMarkTarget vumark) { switch (vumark.InstanceId.DataType) { case InstanceIdType.STRING: return vumark.InstanceId.StringValue; } return ""; } }
- The second one "Model3DScript" is to enable and disable Gameobject depending on the string value of the detected vumark.
public class Model3DScript : MonoBehaviour { //3d models public GameObject[] Model3D = new GameObject[2]; //3d model of AR
public void Show3Dmodel (string VumarkString) { if (VumarkString = "XXX") { Model3D[0].SetActive(true); } else if (VumarkString = "YYY") { Model3D[0].SetActive(false); Model3D[1].SetActive(true); } } }
I attached two gameobjects to my Array Model3D from the unity Inspector.
My problem is that each time, the Show3Dmodel method is called, I get an error message : "IndexArray is out of range".
I checked the elements of my Model3D array in Debug mode, I have found that my array contain null objects. But in the unity inspector, I see my Model3D in my array.
How can I solve this problem? I don't want to instantiate my Model3D array in the same script of VumarkCheck.