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

Obtaining and dropping a pickup item {SOLVED}

Discussion in 'Scripting' started by milliehashh, Dec 1, 2015.

  1. milliehashh

    milliehashh

    Joined:
    Sep 17, 2015
    Posts:
    72
    I'm making a game for a college brief and in it the player will be able to to press a GUI button to be given a pickup - you'll never actually see the pickup, i just want something to display saying something similar to "pickup obtained" - I'm presuming id do this using a canvas.
    hopefully then the player will be able to walk into a trigger and drop the pickup but I'm not sure how id write the script so that nothing will happen if the player enters the trigger without the pickup and so that this only occurs when you enter one certain trigger.

    i know I'm asking for something kinda big, any help will be greatly appreciated as i have a deadline in 17 days. :(
    Thanks in advance.
     
  2. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    I would do OnTriggerEnter and then have a bool variable named pickedUp. If false, then destroy the gameobject (pickup), while editing an empty text in the canvas, to say "Item picked up". And of course set pickedUp to true
     
  3. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    Oh sorry, I misunderstood it. But it's pretty much something like that. When button in Canvas is pressed, you set a pickupEquipped to true and a fancy text saying "pickup obtained". Then when you do OnTriggerEnter, you check for that bool. If true, then set pickupEquipped to false, and do some fancy text saying "pickup dropped"

    But that's how I would do it. I'm not an expert, but this would work. Sure, there is a much better way of doing it.
     
  4. milliehashh

    milliehashh

    Joined:
    Sep 17, 2015
    Posts:
    72
    Thank you! I'll try this out when I can. :)
     
    mads232 likes this.
  5. milliehashh

    milliehashh

    Joined:
    Sep 17, 2015
    Posts:
    72
    I did this and it worked great - it was exactly what I wanted to do, thanks!! :D
     
  6. mads232

    mads232

    Joined:
    Sep 6, 2013
    Posts:
    48
    No problem :) Glad it worked out for you.