Having trouble with animator and triggers with raycasts on mobile
heres my code
Ray ray;
RaycastHit hit;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update () {
if(Input.touchCount > 0 || Input.GetTouch(0) .phase == TouchPhase.Began)
ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
Debug.DrawRay(ray.origin, ray.direction * 20,Color.red);
if (Physics.Raycast(ray,out hit,Mathf.Infinity))
{
Debug.Log ("Hit Something");
GameObject.Find("Object").GetComponent<Animation>().Play("Die");
}
}
}
This was the code which would delete a game object connected to a collider that the RayCast hit (Destroy(hit.transform.gameObject);) This takes the output from hit variable and destroys gameObject based on if it was hit. What I need is to use the hit variable to trigger an animation when the object gets hit (Dies)
The code that I have in the script (GameObject.Find("Object").GetComponent().Play("Die");) comes up with an error which displays (MissingComponentException: There is no 'Animation' attached to the "GameObjectName" game object, but a script is trying to access it.)
I have the animator window set up with trigger parameters and conditions on the transitions named "Die" which I'm trying to call on from my script.
If anyone could help that would be fantastic.