how to destroy an object once you collide with it the second time?
I've already done something similar but the object would destroy immediately after collision, like this:
private void OnTriggerEnter2D (Collider2D other){
if (other.gameObject.tag == "gemRed") {
GetSpeed (other.GetComponent <SpeedUpScript> ().GetSpeedBoost ());
Destroy (other.gameObject);
}
}
can anyone help? thanks
if it's just one gameobject you collide with, create a bool, set it true if you collid the first time and check for the bool for true. will only be true the second time.
it it's different objects then do the same with a variable of that type, save to it on collision and check for null, OR if it's a whole lot of objects, add them to a list on first contact and always check if the list contains it.
either of those three solutions are false, null or do not contain the collider the first time and should be true, not null or contain the collider the second time.
Your answer
Follow this Question
Related Questions
How would I go about making a spider create a web? 0 Answers
Change partial material color based on overlap (collision) 0 Answers
How to edit collision on objects that aren't spawned yet 0 Answers
Get adjacent objects (tiles) using Colliders? 0 Answers
Move to object if collision is triggered 0 Answers