Search Unity

OnTriggerEnter

Discussion in 'Editor & General Support' started by yellowlabrador, Oct 2, 2006.

  1. yellowlabrador

    yellowlabrador

    Joined:
    Oct 20, 2005
    Posts:
    562
    Hello All,

    Code (csharp):
    1.  
    2. var other : Rigidbody;
    3. var ball = 0.0;
    4.  
    5. function OnTriggerEnter(other : Collider)
    6. {
    7.     ball++;
    8. }
    When I add this script to a empty GO with a sphere collider and IsTrigger is checked, I get an error.

    Thanks,
    Ray[/code]
     

    Attached Files:

  2. yellowlabrador

    yellowlabrador

    Joined:
    Oct 20, 2005
    Posts:
    562
    I got it,

    I was writing some script that had an error (not being used) before I wrote the OnTrigger Script, After the error was corrected, I was able to add the script to the empty GO.

    Hmm..
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Oh, good. :)

    A couple things though...you have "other" defined as a type Rigidbody and later as a type Collider. A variable can only be one type, so just get rid of the first line. If you're just incrementing "ball", it's an integer, so ideally you'd use "var ball: int = 0", instead of 0.0 which means floating point. (I'm assuming Unity processes integers faster than floats...not that it will make any noticeable difference in this case, but still, good to get in the habit I guess.)

    --Eric
     
  4. yellowlabrador

    yellowlabrador

    Joined:
    Oct 20, 2005
    Posts:
    562
    Hi Eric5h5,

    Thanks for the tip.