Hello, i have been wracking my brain to get my animation to play when my VR reticle hits an object.
I have an animation in game, with apply root motion turned off, when turned on the animation plays over and over.
My object has an animator, my VR camera has a script on with the ray casting working already, which i am able to interact with an object to enable and object but playing the animation has me stumped. here is my untidy code where i have tried most things haha.
The if statement works, the debug shows me hitting the NextTank
public Camera _cam;
public GameObject Board;
public bool TankSwitch;
//public BoxCollider Board_B;
private Vector2 centerOfScreen;
public GameObject tankOne;
Animator GoingDown;
//public float Distance;
// Use this for initialization
// Use this for initialization
void Start()
{
//tankOne = GameObject.Find("FirstTank");
GoingDown = tankOne.GetComponent<Animator>();
//GoingDown = GetComponent<Animator>;
//GoingDown = GetComponent<Animator>();
//Animator jumpHash = Animator.StringToHash("GoingDown");
//gameObject.SetActive(false);
//Board_Body = Board.GetComponent<Gameobject>();
//Rigidbody Board = GetComponent<Rigidbody>();
centerOfScreen = new Vector2((float)VRSettings.eyeTextureWidth / 2, (float)VRSettings.eyeTextureHeight / 2);
GoingDown.Play("GoingDown");
}
void update()
{
if (hit.collider.gameObject.tag.Equals("NextTank"))
{
//tankOne.GetComponent<Animation>().play();
//tankOne = gameObject.GetComponent("GoingDown");
print("I'm looking at " + hit.transform.name);
GoingDown.Play("GoingDown");
//tankOne.PlayAnimation();
//GoingDown.StartPlayback();
//tankOne.transform.position = new Vector3(0f, 1f, 0f);
//GoingDown.Play.GoingDown;
//GoingDown.SetBool = ("TankSwitch", true);
//Board.transform.localScale = new Vector3(4, 2, 0);
}
}
}
tankOne is the gameobject with the animation.
I think i just need to access the animator from the object i want to animate, but i am unable to.
Sorry about the wall of text.