I want to destroy the gameobject on the 3rd collision with enemy
2d game
using UnityEngine;
using System.Collections;
public class hok : MonoBehaviour
{
public float upForce; //upward force of the "flap"
public float downForce;
public float forwardSpeed; //forward movement speed
public bool isDead = false; //has the player collided with a wall?
Animator anim; //reference to the animator component
bool flap = false; //has the player triggered a "flap"?
/*remeber the upforce +forward make large impact on style of this game mainly the upforce so adjust accordingly and
mixmatch these with gravity and mass weights under htis rb2d in inspectore*/
void Start()
{
//get reference to the animator component
anim = GetComponent<Animator> ();
//set the bird moving forward
GetComponent<Rigidbody2D>().velocity = new Vector2 (forwardSpeed, 0);
}
void Update()
{
//don't allow control if the bird has died
if (isDead)
return;
//look for input to trigger a "flap"
if (Input.GetKeyDown("g"))
flap = true;
}
void FixedUpdate()
{
if (flap)
{
flap = false;
anim.SetTrigger ("Flap");
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, 0);
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, upForce));
}
if (Input.GetKeyDown("t"))
{
//...zero out the dog current y velocity before...
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 0);
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (-0, downForce));
}
}
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag == "Wall")
{
//if the bird collides with something set it to dead...
//isDead = true;
GetComponent<AudioSource>().Play();
//...tell the animator about it...
//anim.SetTrigger ("Die");
//...and tell the game control about it
}
}
}