Vector3 velocity = Vector3.zero;
public float flapSpeed = 50f;
public float forwardSpeed = 1f;
bool didFlap = false;
Animator animator;
bool dead = false;
// Use this for initialization
void Start () {
animator = transform.GetComponentInChildren< Animator >();
if( animator == null )
{ Debug.LogError( "Unable to find Animator!" ); }
}
//Do Graphic & Input updates here
void Update(){
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) {
didFlap = true;
}
}
// Do physics engine updates here
void FixedUpdate () {
if (dead)
return;
gameObject.GetComponent<Rigidbody2D>().AddForce(Vector2.right * forwardSpeed);
if(didFlap) {
gameObject.GetComponent<Rigidbody2D>().AddForce(Vector2.up * flapSpeed);
didFlap = false;
animator.SetTrigger("DoFlap");
}
if(gameObject.GetComponent<Rigidbody2D>().velocity.y >0) {
transform.rotation = Quaternion.Euler(0, 0, 0);
}
if(gameObject.GetComponent<Rigidbody2D>().velocity.y >0) {
float angle = Mathf.Lerp(0, -25, -gameObject.GetComponent<Rigidbody2D>().velocity.y / 4f );
transform.rotation = Quaternion.Euler(0, 0, angle);
}
}
void OnCollisionEnter2D(Collider2D collision) {**ERROR**
animator.SetTrigger("Death");**ERROR**
dead = true;
}
}