Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Trigger/Collision

Discussion in 'Scripting' started by kwabbott, Dec 4, 2007.

  1. kwabbott

    kwabbott

    Joined:
    Jun 5, 2007
    Posts:
    151
    I've written a simple script to detect when the player object makes contact with another object. I only want the script to execute when the object with the player tag is the trigger.

    Code (csharp):
    1.  
    2. function OnTriggerEnter (other : Collider) {
    3. if (other.CompareTag ("Player")) {
    4.     PlayerScore.score = PlayerScore.score-damageMultiplier;
    5. }
    6. }
    7.  
    My problem is I'd like the object with the script to maintain it's rigid body properties, but IsTrigger disables this. When I try to use OnCollisionEnter instead I get a Script Error that seems to be associated with trying to identify the tagged player object.

    Can anyone tell me what the syntax would be to use OnCollisionEnter with an if statement identifying the object with the player tag?

    thanks

    Kevin
    [/quote][/code]
     
  2. bronxbomber92

    bronxbomber92

    Joined:
    Nov 11, 2006
    Posts:
    890
    Code (csharp):
    1. function OnCollisionEnter( collision : Collision )
    2. {
    3.      if( collision.gameObject.CompareTag( "Player" )
    4.           PlayerScore.score = PlayerScore.score-damageMultiplier;
    5. }
    Hope this helps :)
     
  3. kwabbott

    kwabbott

    Joined:
    Jun 5, 2007
    Posts:
    151
    Perfect - thank you so much!

    Kevin
     
unityunity