- Home /
 
               Question by 
               paulgrasser2 · Dec 29, 2018 at 08:20 AM · 
                collisioncooldown  
              
 
              Add Cooldown Between collisions
I'm creating a snake-like game and the score should decrease when the head of the snake ("Player" gameobject) hits the tail, and then there should be a cooldown, otherwise the score will go down by about 50 points, even though it should only go down by one.
Here's my code:
 public class Tail : MonoBehaviour {
     // Use this for initialization
     public bool is_first_few;
     public int index;
     bool cantDie = true;
     [System.NonSerialized] public bool coolingDown = false;
     int timesKilled = 0;
     private bool c = false;
     void Start () {
         
     }
     void OnTriggerEnter2D(Collider2D other)
     {
         //print("COOLDOWN: "+coolingDown);
         //print("TRIGGERRED");
         
         
         if (other.gameObject.name == "Player") {
             //print("DED. COllided with tail index: "+index.ToString()); 
             //print(this.gameObject);
             //print(other.gameObject);
             if (is_first_few == false){
                 if(c == false ){
                     other.GetComponent<NormalFox>().score--;
                     //print("Score --");
                     CoolDown();
                     //coolingDown =true;
                     timesKilled++;
                 }
             }
             
         }else if(other.gameObject.name.Contains("Wolf")){
             if(coolingDown == false){
                 other.GetComponent<Wolf>().DecrScore();
                 //coolingDown =true;
                 timesKilled++;
             }    
         }
     }
     void CoolDown(){
         c = true;
         print("COOLING DOWN");
         Invoke("CoolDownPtwo", 1f);
         
     }
     void CoolDownPtwo(){
         c = false;
         timesKilled = 0;
     }
     // Update is called once per frame
     void Update () {
         
     }
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                