Log in or register to post comments

virtual button press in order

September 23, 2020 - 10:08am #1

Hi,

i need to stack buttons in an arrangement but i need to filter the buttons to determine onButttonPreseed event, like this.



i have 3 virtual button in vuforia unity

i need to enable just button 1 and disable button 2 and 3.

when button 1 pressed, play the walk animation then destroy the button 1, and enable the button 2.

when button 2 pressed, play the jump animation then destroy the button 2, and enable the button 3.

when button 3 pressed, play the run animation then destroy the button 3, and enable the button 1.

i want your helps to know how i can do it in c# script.

 

Thank you.

virtual button press in order

September 25, 2020 - 1:24pm #3

Perfect !!

I got the idea and its work fine.

Thank You Sebben :)

virtual button press in order

September 24, 2020 - 12:42am #2

Hi,

if I understood right you want to place 3 virtual buttons on one image target. You can add a couple of thing to the VirtualButtonEventHandler like this:

public GameObject Button1;
    public GameObject Button2;
    public GameObject Button3;
    Animation anim;
    public AnimationClip walk;
    public AnimationClip jump;
    public AnimationClip run;
    public GameObject AnimationObject;
    int i = 0;
void Start() {
        Button3.GetComponent<VirtualButtonBehaviour>().enabled = false;
        Button2.GetComponent<VirtualButtonBehaviour>().enabled = false;
        anim = AnimationObject.GetComponent<Animation>();
    } 
public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonPressed: " + vb.VirtualButtonName);

        SetVirtualButtonMaterial(m_VirtualButtonDefault);

        if (i == 0)
        {
            anim.clip = walk;
            anim.Play();
        }
        else if(i==1)
        {
            anim.clip = jump;
            anim.Play();
        }
        else if (i == 2)
        {
            anim.clip = run;
            anim.Play();
        }
        i++;


        StopAllCoroutines();

        BroadcastMessage("HandleVirtualButtonPressed", SendMessageOptions.DontRequireReceiver);
    }

public void OnButtonReleased(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonReleased: " + vb.VirtualButtonName);
       

        SetVirtualButtonMaterial(m_VirtualButtonDefault);

        StartCoroutine(DelayOnButtonReleasedEvent(m_ButtonReleaseTimeDelay, vb.VirtualButtonName));

        Button1.GetComponent<VirtualButtonBehaviour>().enabled = false;

        if (i == 1)
        {
            Button2.GetComponent<VirtualButtonBehaviour>().enabled = true;
        }
        else if (i == 2)
        {
            Button2.GetComponent<VirtualButtonBehaviour>().enabled = false;
            Button3.GetComponent<VirtualButtonBehaviour>().enabled = true;
        }
    }

The script should be on your Image Target. Then drag your animation clips, the virtual buttons and the object you want to animate in the right fields.

Log in or register to post comments