Search Unity

Need help on my pickup Script, cant set an asset to active

Discussion in 'Scripting' started by AndrewMac26, Nov 28, 2015.

  1. AndrewMac26

    AndrewMac26

    Joined:
    Nov 24, 2015
    Posts:
    14
    So im pretty new to unity and for seem reason I can't get this pickup script to work. Im trying to make it so that when the player collides with a torch asset within the world the world object disappears and an inactive object positioned in front of the camera is activated, creating the illusion the character has picked up the torch. The world torch disappears but the camera torch doesn't activate can anyone tell me why? The collider works fine also so im really sure what this issue is:

    Code (CSharp):
    1. void OnControllerColliderHit(ControllerColliderHit hit)
    2.     {
    3.         if (hit.gameObject.name == "worldTorch")
    4.         {
    5.             Debug.Log("Object picked up " + hit.gameObject.name);
    6.             Destroy(hit.gameObject);
    7.             Torch.SetActive(true);
    8.         }
    9.     }

    so the "Torch" is the one in front of the player and worldTorch is the one in the world with the collider etc


    Thanks
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    In the inspector window for this script instance, did you drag a reference to the Torch that you want to turn on?

    Do you get any exceptions or other errors displayed in the log next to "Object picked up ..." in the log?
     
  3. AndrewMac26

    AndrewMac26

    Joined:
    Nov 24, 2015
    Posts:
    14
    Thanks actually because of your post I realised I had selected the torch from the assets tab instead of the scene tab works now thanks for your help :)