Unity Community


Results 1 to 4 of 4

  1. Posts
    216

    how do i activate a gameobject?

    well.. i unchecked that box in the inspector



    and i made a script like this

    Code:  
    1. function Update () {
    2.  
    3. if (Input.GetButtonDown ("shoot")) {
    4.  
    5. GameObject.Find("NEWPOINT").active = true;
    6.  
    7. }
    8. }

    but i doest not work.. am i doing something wrong?


  2. Location
    Bay Area Hobbyist
    Posts
    495
    There's a gotcha with Find that you just hit:

    http://unity3d.com/support/documenta...ject.Find.html

    If no game object with name can be found, null is returned. If name contains a '/' character it will traverse the hierarchy like a path name. This function only returns active gameobjects.


  3. Posts
    216
    so the gameObject.Find only finds active objects.. and thats why is not fidning the NEWPOINT because he is unchecked..

    damm...


  4. Location
    USA
    Posts
    1,224
    You can still activate the object, just get a reference to the object a different way (such as assigning it in the inspector).

    Code:  
    1.  
    2. function Update (){
    3.     if (Input.GetButtonDown("Jump")) target.active = true;
    4. }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •