Search Unity

How to use Sphere colliders to detect the "Player"

Discussion in 'Scripting' started by Whatee, Feb 24, 2010.

  1. Whatee

    Whatee

    Joined:
    Feb 22, 2010
    Posts:
    10
    can someone break this down for me and explain this further?

    Use triggers. A simple sphere trigger can work wonders though. You get OnTriggerEnter/Exit calls when exiting the sphere of influence you want

    Code (csharp):
    1. function OnTriggerEnter (c : Collider)
    2. {
    3.     if (c.CompareTag("Player"))
    4.         enabled = true;
    5. }
    6.  
    7. function OnTriggerExit (c : Collider)
    8. {
    9.     if (c.CompareTag("Player"))
    10.         enabled = false;
    11. }
    12.  
    Everytime i try and this script in, iget a lot of errors and i must be doing something wrong.
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Which errors are you getting?