- Home /
How to make game object 1 able to destroy game object 2 if it was given some sort of power up?
Currrently Im making an endless dodging game where basically you just need to dodge incoming enemies. mid way through, I thought of adding a power up feature where if the player got it, the player would become invincible against the enemy, but then when the enemy hits the player nothing happened and the enemy would just roll away. I mean sure the player is invincible but it is WAY too anticlimatic.
and so i wanted to create a situation where if the player got that power up and got hit by the enemy it would destroy the enemy object immidiately, but so far I've been stuck.
so far i only thought of this public GameObject VaccineDestroyVirusObject; public void OnCollisionEnter(Collision collision) { if (collision.collider.CompareTag("Vaccine")) { //destroy vaccine object (POWER-UP) Destroy(collision.collider.gameObject); //Destroy Virus upon contact with player (ENEMY [NOT WORKING]) DestroyVirus(); } } void DestroyVirus() { Destroy(VaccineDestroyVirusObject); }
So I wonder if anybody had faced something similar to me and found a solution, if so your help would be much appreciated.
thank you very much. : )
Your answer
Follow this Question
Related Questions
transferring variables between scripts c# 3 Answers
Can you destroy an object using GetInstanceID? 0 Answers
Destroying Assests Not Permitted 1 Answer
Unity createNew Game Object after calling a Destroy() 1 Answer
Script doesn't work anymore! 2 Answers