top of page

Animations 101


Moving from simple GameObject shapes as your interactive players and enemies isn't as hard as it seems.

You'll need to download Assets from unity that contain different models and animations.

Drag a model and Create>Animator Controller give it a name and add the component Animator to the model. Drag the Animator Controller created to Controller.

Look for the Animations folder in the Asset and drag them to the Animator controller flow chart .

To run towards the mouse position you'll need the following code added to your player called AniPlayer:

 

using System.Collections; using System.Collections.Generic; using UnityEngine; public class AniPlayer : MonoBehaviour { Animator AnimationP; // Use this for initialization void Start () { AnimationP = GetComponent<Animator> (); } // Update is called once per frame void Update () { //if (Input.GetKey (KeyCode.Mouse0)) avance con click de mouse if (Input.GetKey (KeyCode.UpArrow)) { transform.Translate (Vector3.forward * Time.deltaTime, Space.Self); AnimationP.Play ("running"); } else { AnimationP.Play ("idle"); } } }

 

Extra!

Detect Collision with Animated models:

It's very important to add colliders to your enemy's in order to detect the collision with the bullet.**

 

using System.Collections; using System.Collections.Generic; using UnityEngine; public class CollisionE : MonoBehaviour { public int score = 2; Animator Animation; // Use this for initialization void Start () { Animation = GetComponent<Animator> (); } // Update is called once per frame void Update () { } void OnCollisionEnter (Collision c){ if (c.transform.name == "Capsule(Clone)") { Destroy (c.gameObject); Destroy (this.gameObject); score--; if (score == 1) { print (" score es 1"); Animation.Play ("Headspring"); }else if (score == 0){ Animation.Play ("DamageDown"); } } else { } } }

 

bottom of page