Log in or register to post comments

Virtual Buttons Calling OnButtonPressed( ); from Raycast

February 19, 2018 - 8:52pm #1

Hello, i want to call the OnButtonPressed Virtual Button method from A Raycast script, i got an error when i call the OnButtonPressed method due to wrong parameter.

I would like to know the best way to do it and solve my case, maybe i'am doing something wrong, anyone can help me ? 

 

Here is my two Scripts: 

- The Virtual Button Script: 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;

public class VB_Anim : MonoBehaviour, IVirtualButtonEventHandler {

    public GameObject vbBtnObj;

    public Animator immoAni;

// Use this for initialization

void Start () {

        vbBtnObj = GameObject.Find("Vb_Rotate");

        vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);

        immoAni.GetComponent<Animator>();

}

    public void OnButtonPressed(VirtualButtonBehaviour vb)

    {

        immoAni.enabled = true;

        immoAni.Play("immo_rotate_animation");

        Debug.Log("BTN Pressed the Animation is running");

    }

    public void OnButtonReleased(VirtualButtonBehaviour vb)

    {

        immoAni.enabled = false;

        Debug.Log("BTN Released the Animation is on Pause");

    }

    // Update is called once per frame

    void Update () {

      

    }

}

 

The RayCast Script: 

using UnityEngine;

using System.Collections;

using Vuforia;

public class ObjectHighlighter : MonoBehaviour {

public Animator anim;

    public GameObject vbBtnObj;

   

    // Use this for initialization

    void Start () {

    }

void Update () {

  foreach (Touch touch in Input.touches)

  {

   Debug.Log("ok...");  

   if (touch.phase == TouchPhase.Began)

   {

    Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);

                RaycastHit hit = new RaycastHit();

    if (Physics.Raycast(ray, out hit, 100000))

    {

                   

                   //My error is here

                    vbanimscript.OnButtonPressed( ...);

                }

   }

  }

}

}

Virtual Buttons Calling OnButtonPressed( ); from Raycast

February 20, 2018 - 4:09pm #2

Hello Disruptive,

A virtual button is meant to be triggered by occluding the designated section of the Image Target. The method you are trying to trigger the button press from sounds more aligned with the built in Unity UI Button. Have you tried using that for this purpose instead?

Thanks,

Vuforia Support

Log in or register to post comments