Instantly share code, notes, and snippets.

Embed
What would you like to do?
VirtualButtonEvent.cs
using System.Collections.Generic;
public class VirtualButtonEvent : MonoBehaviour, IVirtualButtonEventHandler {
private GameObject Sphere;
// register buttons for event handling
void Start() {
VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
for (int i = 0; i < vbs.Length; ++i) { vbs[i].RegisterEventHandler(this); }
Sphere = transform.FindChild("Sphere").gameObject;
}
// button is "pressed" so change color of Sphere
public void OnButtonPressed(VirtualButtonAbstractBehaviour vb) {
if (vb.VirtualButtonName=="Red") { Sphere.renderer.material.color = Color.red; }
if (vb.VirtualButtonName=="Blue") { Sphere.renderer.material.color = Color.blue; }
}
// change Sphere back to white
public void OnButtonReleased(VirtualButtonAbstractBehaviour vb) {
if (vb.VirtualButtonName=="Red") { Sphere.renderer.material.color = Color.white; }
if (vb.VirtualButtonName=="Blue") { Sphere.renderer.material.color = Color.white; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment