My goal is to have multiple enemy prefabs with the same script and call their script.
Sorry if this is confusing but I want to be able to have the same enemy with the same script and no change except when collided with by the bullet they will all die the same way without having do something special for each one. I have no problem with having to set up a script for each one, but I just feel there may be an easier way. My current script on the bullet is
void OnCollision2D (Collision col){
if (col.gameObject.name == "Enemy") {
enemyscript.kill ();
Destroy(gameObject);
And as of now all of the enemy are named enemy and are all attached to the same enemyscript which destroys them. Thanks ahead of time.
Answer by Umresh · Sep 09, 2015 at 05:21 AM
Get the Script from the Collided object i.e. enemy.
if (col.gameObject.name == "Enemy") {
col.gameObject.GetComponent<enemyScript>().kill (); // Like this get the component
Destroy(gameObject);
}
Your answer
Follow this Question
Related Questions
When enemy spawns it loses the script settings. 0 Answers
Score counter not working properly. 1 Answer
How to get in enemy to stop after a certain distance from the player? 0 Answers
Destroy a Prefab from an Array? (C#) 2 Answers
Make a game object face another game object when instantiated 2 Answers