Stop animation when bullet collides with target
Hi all,
So I'm very new to Unity and have been having a lot of issues trying to get my animation to stop when the bullet collides with the target as I want it to move around to add some difficulty to the game. Heres the code I've been using:
using UnityEngine; using System.Collections;
public class Cowboy : MonoBehaviour {
// Use this for initialization
void Start () {
animation.Play ("Cowboy");
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter (Collision col)
{
if (col.gameObject.name == "Bullet") {
animation.Stop ("Cowboy");
}
}
}
The script is a component of the target, please let me know if what I wrote is terrible as I'd like to get better at scripting. Thanks!
Your answer
Follow this Question
Related Questions
Unable to stop animation upon collision (2d, animation, rigidbody) 0 Answers
Rotating a character with character controller when colliding a wall. 1 Answer
Collision or Triggers both not working. 3D. 1 Answer
How can I implement box collider or mesh collider in this code? 0 Answers
Collisions without colliders 0 Answers