Mover y animar un personaje
using UnityEngine;
using System.Collections;
public class Character : MonoBehaviour {
private Vector3 move;
private Animator animbraid;
private int speed;
private int speed2;
public static int score;
// Use this for initialization
void Start () {
animbraid = GetComponent<Animator> ();
speed = 3;
speed2 = 7;
score = 0;
}
// Update is called once per frame
void Update () {
animbraid.SetBool ("Idle", true);
animbraid.SetBool ("Walk", false);
animbraid.SetBool ("Jump", false);
if (Input.GetKey (KeyCode.D)) {
animbraid.SetBool ("Idle", false);
animbraid.SetBool ("Walk", true);
animbraid.SetBool ("Jump", false);
transform.Translate (Vector3.right * Time.deltaTime * speed);
transform.rotation = Quaternion.Euler (new Vector3 (0, 0, 0));
}
if (Input.GetKey (KeyCode.A)) {
animbraid.SetBool ("Idle", false);
animbraid.SetBool ("Walk", true);
animbraid.SetBool ("Jump", false);
transform.Translate (Vector3.right * Time.deltaTime * speed);
transform.rotation = Quaternion.Euler (new Vector3 (0, 180, 0));
}
if (Input.GetKey (KeyCode.W)) {
animbraid.SetBool ("Idle", false);
animbraid.SetBool ("Walk", false);
animbraid.SetBool ("Jump", true);
transform.Translate (Vector3.up * Time.deltaTime * speed2);
}
}
void OnTriggerEnter2D(Collider2D other){
if (other.gameObject.tag=="Coin"){
score=score+1;
}
if (other.gameObject.tag=="Coin"){
Destroy (other.gameObject);
}
if (other.gameObject.tag == "Enemy") {
Application.LoadLevel(Application.loadedLevel);
}
}
}