I added the cube on the image target of Vuforia. I also added the Vuforia virtual button on the image target. Now I want to rotate the cube by pressing virtual button. For this purpose I implemented the following script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class rotate : MonoBehaviour, IVirtualButtonEventHandler {
public GameObject vbtn;
public GameObject cube;
public Renderer rend;
// Use this for initialization
void Start () {
vbtn = GameObject.Find ("virtualbtn5");
vbtn.GetComponent<VirtualButtonBehaviour> ().RegisterEventHandler (this);
cube = GameObject.Find ("Cube");
rend = cube.GetComponent<Renderer>();
}
public void OnButtonPressed(VirtualButtonBehaviour vb){
Debug.Log ("Button pressed");
cube.transform.Rotate (new Vector3(0,Time.deltaTime*1000,0));
rend.material.color = Color.blue;
}
public void OnButtonReleased(VirtualButtonBehaviour vb){
Debug.Log ("Button released");
rend.material.color = Color.red;
}
}
The button seems to be working because the Debug.Log ("Button pressed");
and rend.material.color = Color.blue;
statements in onButtonPressed
function are working fine. But cube.transform.Rotate (new Vector3(0,Time.deltaTime*1000,0));
for rotating cube does not work.
Simple is that the button can change the color of the cube but it does not rotate the cube.