Script error: OnCollisionEnter2D This message parameter has to be of type: Collision2D The message will be ignored.
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;
}
}
Comment
http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnCollisionEnter2D.html
In OnCollisionEnter2D you need to use Collision2D object as parameter not Collider2D
Hope it helps you
Answer by ArtBIT · May 10, 2017 at 03:04 PM
As the error suggests you are using Collider2D instead of Collision2D as the parameter type for the OnCollisionEnter2D method, try:
void OnCollisionEnter2D(Collision2D collision) {
animator.SetTrigger("Death");
dead = true;
}
Your answer
Follow this Question
Related Questions
Image appearing after clicking a button 1 Answer
How to get the object to move only when I click on it and not just anywhere else? 1 Answer
Weapon following mouse and orbiting Player 1 Answer
2D How to set a limit to the rotation of my cube, when dragging with mouse 0 Answers
Camera movement 1 Answer