Search Unity

invisibility script won't work

Discussion in 'Scripting' started by Hard target, Aug 19, 2014.

  1. Hard target

    Hard target

    Joined:
    Oct 31, 2013
    Posts:
    132
    My invisibility script won't work.
    Code (CSharp):
    1. #pragma strict
    2. var detector : GameObject;
    3. function OnTriggerEnter (hit : Collider)
    4. {
    5.  
    6.     detector = GameObject.FindGameObjectWithTag("Unobserved");  
    7.     if(hit.gameObject == "Unobserved")
    8.     {
    9.         hit.gameObject.renderer.enabled = false;
    10.     }
    11. }
    12.  
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    I don't think a gameObject can have a name.

    Try, hit.transform.name
     
  3. Hard target

    Hard target

    Joined:
    Oct 31, 2013
    Posts:
    132
    You mean line six.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    depending what youre checking (i suspect tag)

    hit.gameObject.tag

    or

    hit.gameObject.name
     
  5. Hard target

    Hard target

    Joined:
    Oct 31, 2013
    Posts:
    132
    I used Component.CompareTag to do it.But thanks for the help.
    Here is the code.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. function OnTriggerEnter (other : Collider) {
    4.         if (other.CompareTag ("Player")) {
    5.  
    6.              gameObject.renderer.enabled = false;
    7.     }
    8. }