Log in or register to post comments

ImageTarget

November 7, 2016 - 5:38am #1

hi

I have some problems about image target...

on this code...I have 2 targets and I want to use them on a imagetarget...If device perceive "xxx" image,I will create cube or  If device perceive "yyy" image,I will create sphere...

but This code perceive only first "if"...doesnt work second "if"

Can you help me ? Please give me advise....

 

using UnityEngine;

using System.Collections;

using System.Collections.Generic;



public class DynamicTargets : MonoBehaviour {

    

    private bool ObjectCreated = false;

    

    

    // Update is called once per frame

    void Update ()

    {

        IEnumerable<TrackableBehaviour> trackableBehaviours = TrackerManager.Instance.GetStateManager().GetActiveTrackableBehaviours();

 

        // Loop over all TrackableBehaviours.

        foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours)

        {

            string name = trackableBehaviour.TrackableName;

            Debug.Log ("Trackable name: " + name);

            

            if (name.Equals("xxx") && !ObjectCreated)

            {

             

                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

                // attach cube under target

                cube.transform.parent = trackableBehaviour.transform;

                

                // Add a Trackable event handler to the Trackable.

                // This Behaviour handles Trackable lost/found callbacks.

                trackableBehaviour.gameObject.AddComponent<DefaultTrackableEventHandler>();

                

                // set local transformation (i.e. relative to the parent target)

                cube.transform.localPosition = new Vector3(0,0.2f,0);

                cube.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);

                cube.transform.localRotation = Quaternion.identity;

                cube.gameObject.SetActive(true);

                

                ObjectCreated = true;

            }

else if (name.Equals("yyy") && !ObjectCreated)

            {

            

                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

                // attach cube under target

                cube.transform.parent = trackableBehaviour.transform;

               

                // Add a Trackable event handler to the Trackable.

                // This Behaviour handles Trackable lost/found callbacks.

                trackableBehaviour.gameObject.AddComponent<DefaultTrackableEventHandler>();

               

                // set local transformation (i.e. relative to the parent target)

                cube.transform.localPosition = new Vector3(0,0.2f,0);

                cube.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);

                cube.transform.localRotation = Quaternion.identity;

                cube.gameObject.SetActive(true);

               

                ObjectCreated = true;

            }

        }

    }

}

Log in or register to post comments