Search Unity

Checking for Scripts in colliding gameobjects.

Discussion in 'Scripting' started by isse26, Jan 20, 2014.

  1. isse26

    isse26

    Joined:
    Dec 8, 2013
    Posts:
    30
    Hi
    I need to check my OnTriggerEnter thing if it contains the script "PhysicsGround.cs" and then take the gamobject that I collided with and assign it to a varieble.

    Please help and excuse my bad english.
     
  2. suspensemusic

    suspensemusic

    Joined:
    Dec 4, 2013
    Posts:
    41
    You could tag every object that contains that script with the same tag..

    Something like make the tag "Ground"

    Then in your code do something like

    Code (csharp):
    1.  
    2. void OnTriggerEnter (Collider other){
    3. if (other.tag = "Ground"){
    4. //action here
    5. }
    6. }
    7.  
     
  3. TheShane

    TheShane

    Joined:
    May 26, 2013
    Posts:
    136
    Can't you just use GetComponent<PhysicsGround>() on the object you collided with?

    If it doesn't exist, it returns null so check the return value. If it does, assign the object to your variable.