How do i look at a object, press E and turn on it’s animation?
What I would do is this:
- Raycast from the camera foward into the scene
- Then, if E is pressed get the GameObject from the collider
- Play it’s animation
In code form:
if (Input.GetKeyDown(Keys.E))
{
var hit : RaycastHit;
if (Physics.Raycast(new Ray(transform.position, transform.fwd, hit)
{
hit.collider.gameObject.animation.Play("NameOfAnimation");
}
}