Quantcast
Channel: Answers by "TheShadyColombian"
Viewing all articles
Browse latest Browse all 100

Answer by TheShadyColombian

$
0
0
Right now, you're defining a single instance of the EnemyHealthManager script in your start function. Not only will this exclude all health-diminishing functions to one instance, It also won't work if the player's not spawned the moment that function is called. What you want to do is to get the script instance of the object currently being attacked. To do this, use the parameter sent from the OnCollitionEnter2D function (in this case, *Collision2D other*): EnemyHealthManager healthManagerInstance = other.collider.GetComponent (); //Use the newly created variable in place of theenemyhealthmanager This code snipped (which goes inside your *if* statement inside the *OnCollisionEnter2D* function) takes the collision, gets it's collider (the enemy/object you hit) and then gets an *EnemyHealthManager* script attached to it. I suggest you also add an if statement to verify it *GetComponent* returns null to avoid *NullReferenceException* errors. Good luck! Let me know if you need follow-up help

Viewing all articles
Browse latest Browse all 100

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>