Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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:
    36,797
    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 :)