Tagging a collider and destroying it
void OnCollisionEnter(Collider other){ if (other.gameObject.tag == "Player") { Destroy (other.gameObject); } }
here is my collision script I am making a fps multiplayer game and this is the script for destroying the other player when that player is hit
I have tagged the player
would you bother explaining what you want us to answer? Do you perhaps want to destroy the collider itself? other.gameObject.getcomponent<> would select any components on the other object.
Answer by Firedan1176 · Dec 22, 2015 at 08:08 PM
For starters, OnCollisionEnter takes in a Collision, not a Collider, so just replace Collider with Collision.
Does that fix your problem?
Note: It'd be better to use:
 if(other.gameObject.CompareTag("Player"))
 
               because comparing strings with equals signs don't always work correctly.
nah did not work I need it for a multiplayer game so I changed it over to the player and here is the code now
 void OnCollisionEnter(Collision other) {
         if(other.gameObject.CompareTag("Bullet")){
                 print ("Hit a player!");
                 Destroy (other.gameObject);
                 Network.Disconnect ();
         }
         else if (!other.gameObject.CompareTag("Bullet")){
                 print ("$$anonymous$$issed A Player!");
         }
             if (other.gameObject.CompareTag("Destroyer")) {
                 Network.Disconnect ();
                 Destroy (gameObject);
             }
     }
                 Your answer
 
             Follow this Question
Related Questions
How to damage player when bullet collides with player. 0 Answers
RPC sending Failed 0 Answers
Question on Networking for a multiplayer game (making a board game) 0 Answers
my network spawn bullet flys off in server but drop like a water in client 0 Answers
How do I have my character aim where my mouse cursor is? 2 Answers