I want just animate only one robot when his button is pressed. Problem: that all 6 robots start animation when I press one of the six buttons.
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Vuforia;
public class vb_robotsbuttons : MonoBehaviour, IVirtualButtonEventHandler{
public GameObject vbBtnObjFrost, vbBtnObjSpawn, vbBtnObjOrc, vbBtnObjDarkelf, vbBtnObjLittlejaime, vbBtnObjRobbieknight;
public Animator FrostAni, SpawnAni, OrcAni, DarkelfAni, LittlejaimeAni, RobbieKnightAni;
// Use this for initialization
void Start()
{
vbBtnObjFrost = GameObject.Find("Frostbtn");
vbBtnObjSpawn = GameObject.Find("Spawnbtn");
vbBtnObjOrc = GameObject.Find("Orcbtn");
vbBtnObjDarkelf = GameObject.Find("Darkelfbtn");
vbBtnObjLittlejaime = GameObject.Find("Littlejaimebtn");
vbBtnObjRobbieknight = GameObject.Find("Robbieknightbtn");
vbBtnObjFrost.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
vbBtnObjSpawn.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
vbBtnObjOrc.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
vbBtnObjDarkelf.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
vbBtnObjLittlejaime.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
vbBtnObjRobbieknight.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
FrostAni.GetComponent<Animator>();
SpawnAni.GetComponent<Animator>();
OrcAni.GetComponent<Animator>();
DarkelfAni.GetComponent<Animator>();
LittlejaimeAni.GetComponent<Animator>();
RobbieKnightAni.GetComponent<Animator>();
}
public void OnButtonPressed(VirtualButtonBehaviour vb)
{
FrostAni.Play("FrostAnimation");
//Debug.Log("Button Pressed");
SpawnAni.Play("MrSpawn");
//Debug.Log("Button Pressed");
OrcAni.Play("NinjaOrc");
//Debug.Log("Button Pressed");
DarkelfAni.Play("DarkElf");
//Debug.Log("Button Pressed");
LittlejaimeAni.Play("LittleJamie");
//Debug.Log("Button Pressed");
RobbieKnightAni.Play("RobbieKnight");
Debug.Log("Button Pressed");
}
public void OnButtonReleased(VirtualButtonBehaviour vb)
{
FrostAni.Play("NoneFrost");
//Debug.Log("Button Released");
SpawnAni.Play("NoneSpawn");
//Debug.Log("Button Released");
OrcAni.Play("NoneOrc");
//Debug.Log("Button Released");
DarkelfAni.Play("NoneDarkelf");
//Debug.Log("Button Released");
LittlejaimeAni.Play("NoneLittlejaime");
//Debug.Log("Button Released");
RobbieKnightAni.Play("NoneRobbieKnight");
Debug.Log("Button Released");
}
// Update is called once per frame
void Update()
{
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612201632im_/https://answers.unity.com/themes/thub/images/avi.jpg)