How To Pick Up an Item - Unity

Поділитися
Вставка
  • Опубліковано 20 жов 2024
  • Subscribe & Like for more Content like this.
    -------------------------------------------------------------
    UA-cam : / gunzzyt
    twitch : / gunzz___
    FlashLight: assetstore.uni...
    FPS Controller: assetstore.uni...

КОМЕНТАРІ • 86

  • @Ronoiscool
    @Ronoiscool 3 місяці тому +22

    For anyone who is lazy just like me. I wrote the script for you guys. also it says block for example pickupblock. you dont have to replace block with the name of the item just leave it. becuase it will still work. also this one is the one with the one that says e to pick up. if you dont want that. just dont add a canvas. alright. enjoy!
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class PickUpBlock : MonoBehaviour
    {
    public GameObject pickUpText;
    public GameObject BlockOnPlayer;
    void Start()
    {
    pickUpText.SetActive(false);
    }
    private void OnTriggerStay(Collider other)
    {
    if (other.gameObject.CompareTag("Player"))
    {
    pickUpText.SetActive(true);
    // Check if 'E' key is held down to pick up the Block
    if (Input.GetKey(KeyCode.E))
    {
    gameObject.SetActive(false);
    BlockOnPlayer.SetActive(true);
    pickUpText.SetActive(false);
    }
    }
    }
    private void OnTriggerExit(Collider other)
    {
    if (other.gameObject.CompareTag("Player"))
    {
    pickUpText.SetActive(false);
    }
    }
    }

  • @its_nuked
    @its_nuked 7 місяців тому +5

    Felt on the family interrupt and the jet/text outline was funny xDDD
    Ty man :D

  • @francescogamba1301
    @francescogamba1301 Рік тому +3

    If you are having issues with the pickup part just add a rigid body to the battery and disable gravity, everything should work correctly

  • @Infinity-nw1jt
    @Infinity-nw1jt Рік тому +3

    I could not figure this out before and now that I saw that video I want to thank you so much 🙏 ❤❤

  • @hamzaShahid-x5i
    @hamzaShahid-x5i 11 місяців тому +6

    does not seem to be working for me, can I get some help. the code is not allowing me to pick up the torch?

  • @alexplaytop
    @alexplaytop 7 місяців тому +4

    Would be cool to explain how to drop it, after pick up ))

  • @martjaspersalazar2258
    @martjaspersalazar2258 2 роки тому +8

    Your tutorial is really works my friend. Thank you!

    • @GunzzYT
      @GunzzYT  2 роки тому

      You're welcome, im glad it helpt

  • @adammland6924
    @adammland6924 7 місяців тому +1

    thx its very helpful thx very much ... thanks Gunzz very cool . i subbed and liked btw

  • @t.sandwich
    @t.sandwich 7 місяців тому +1

    Dude this is so helpful, thank you :)

  • @Ambersow
    @Ambersow 4 місяці тому

    So helpful and very easy to follow! Keep it up!

  • @REBELHEADGAMES
    @REBELHEADGAMES Рік тому +4

    Is there any chance you can make it that you can ONLY TOGGLE it on and off when you are holding it? Kind regards.

    • @gamerz3d386
      @gamerz3d386 Рік тому

      Try to change the 2nd if condition that is instead of getkey you can try onpresskey
      Something like that and write else after that condition to set false
      Hope this helps
      Thank you

  • @johnlouisedelacruz8905
    @johnlouisedelacruz8905 2 роки тому +3

    thank you so much for your tutorial and it really works!!
    Do you also have a video on how to drop items?

    • @GunzzYT
      @GunzzYT  2 роки тому +1

      You're welcome, maybe i will make a drop system in the near future stay tuned 😁

  • @beefytime1374
    @beefytime1374 Рік тому

    Thank you soo much for this tut it really works and is super easy to follow and i didnt even have a code error even though i still coded i tmyself... thankyou

  • @emeraldwas9k
    @emeraldwas9k Рік тому

    this is really easy thank you and you kinda got me scared at the end lol

  • @WARRIORGUY_YT4789
    @WARRIORGUY_YT4789 2 місяці тому

    Thank you so much that worked my friend!🎉

  • @laetusbeats
    @laetusbeats 10 місяців тому

    ik ruik een beetje Nederlands, dankjewel btw je hebt me echt geholpen!

  • @DaDylanMachine
    @DaDylanMachine Рік тому +4

    Great tutorial, I appreciate it! Quick question, do you believe this method would work when there are multiple objects in the game? I worry that having multiple objects on the controller at all times could pose an issue.

    • @GunzzYT
      @GunzzYT  Рік тому +2

      It only works for picking up a single item. If you want to be able to pick up multiple objects you need to make a empty list and fill the list with the objects that you are picking up and make a riffle trough objects system.

    • @DaDylanMachine
      @DaDylanMachine Рік тому

      @GunzzYT got it, good to know. Thanks for responding

  • @hh5559
    @hh5559 10 місяців тому

    Good tutorial but what I'm struggling is getting the objects to disappear/appear for when one object is dragged into the trigger (OnTriggerEnter)
    I'm trying to drag am object in using Raycast so I can place it in a specific place, using the two-items trick but it won't work for some reason. The original object I'm holding won't disappear and the item that's placed won't appear

  • @Titsou_1
    @Titsou_1 Місяць тому

    how could i make it so Q drops the object?

  • @GMlife317
    @GMlife317 9 місяців тому

    umm for me i dont need to press E its just as soon as you get in the range it gets on your hand

  • @galberger3937
    @galberger3937 Рік тому +1

    Hi.
    can you show how to use a pick up a gun that have a flshlight, how to turn on and off the light of the flashlite and how to shoot while useing the new input system?

  • @abdeali5341
    @abdeali5341 8 місяців тому

    YOUR TUTORIAL ARE REALLY HELPFUL THANKS FOR UPLOADING

  • @lfigure1718
    @lfigure1718 Рік тому +1

    while I dragged in my script, I do not see an option like "Flash Light On Player" for me all I see is the "Script PickUpFlasFlight" how do I get the "Flash Light On Player" while dragging in the script?

    • @GunzzYT
      @GunzzYT  Рік тому

      make sure there are no errors and make the Variables Public not private.

    • @lfigure1718
      @lfigure1718 Рік тому

      @@GunzzYT Got it fixed, turns out there was a bug completely destroying our code but we manage to fix it. Thank you!

  • @onlyrxtro7059
    @onlyrxtro7059 3 місяці тому +1

    Is it a way to make it to where only I can pick it up and nobody else able to touch it even when I drop it

    • @GunzzYT
      @GunzzYT  3 місяці тому +1

      Give your controller the tag MainPlayer and others just Player, then change the tag check in the ontriggerenter to -> if(other.gameObject.tag == "MainPlayer")

  • @Ganiovi
    @Ganiovi 10 місяців тому

    can we use this method to add multiple items to our player and to pick each one at the different time ?

  • @Un_tizio1
    @Un_tizio1 8 місяців тому

    I watches this video like 4 times, i used the code you put in there, i put the tags, the name and everything, but the camera part on the flash light Just doesnt exist for some reason and if i try to start my game It says "All compiler errore have ti be fixed before you can enter playmode! I swear i checked something like 5 times but It Will Say that Every single time. I even tryed to cancel that script and made a new One but there Is Always the same problem. But as i see It worked for everyone so i Just dont see why It doesnt work. Tell me way to fix It please

  • @yourexorcist4436
    @yourexorcist4436 9 місяців тому

    Nice tutorial for picking but as i can see...the light and flashlight doesnt follow you when you rotating the camera...maybe an update of this would be helpfull Thank you very much.

    • @GunzzYT
      @GunzzYT  9 місяців тому +1

      Child it under your Main Camera, that should do the trick.

  • @YusafAnimations
    @YusafAnimations Рік тому

    bro that is genius imma test this tomorrow

  • @mnkvr317
    @mnkvr317 Місяць тому +1

    can you make a tut on inventory?

    • @shark555-q8y
      @shark555-q8y 9 днів тому +1

      i found you on a random video again

  • @malachipeck7450
    @malachipeck7450 Рік тому

    Whenever I try to drag a gameobject to the script it wont let me do it with any objects

  • @parthacodes5893
    @parthacodes5893 Рік тому

    op now i wil implement my own thing like change it to a key and then also make that key trigger doors and chests

  • @ByteWave-fx2zm
    @ByteWave-fx2zm 15 днів тому

    has anyone modified the skript so that you can pick up and drop ?

  • @AnthonyChen-v8q
    @AnthonyChen-v8q 9 місяців тому

    Hi, for some reason my player can't enter inside the box collider of the flashlight, my player is set to the "player" tag, and all the code is correct. Because of this, my text doesn't appear because the player can never enter the confines of the box collider. Are there any components on the player other than the capsule collider and the rigidbody and all the scripts?

    • @GunzzYT
      @GunzzYT  9 місяців тому

      Make sure isTrigger is selected on the boxcollider! if its not your player cannot enter the trigger.

    • @AnthonyChen-v8q
      @AnthonyChen-v8q 9 місяців тому

      @@GunzzYT Yes! That was the issue, thanks you so much, I'm new to unity. Great video by the way!

  • @drake_eric9799
    @drake_eric9799 2 місяці тому

    how to drop the flash light

  • @saadstj7147
    @saadstj7147 Рік тому

    This works just for one item. I tried to pick up more than one item it is not working.

  • @Tricksy_2014
    @Tricksy_2014 Рік тому +1

    With the OnTriggerExit part, it does not work for me. Once I enter, the text stays there. Does anyone have a fix for this?

  • @Rexu3030
    @Rexu3030 Рік тому

    I add this text system in my game and its not working. I have script from your film: "How To Pick Up and Drop Items"

  • @haeqallz19
    @haeqallz19 10 місяців тому

    bro if you dont mind, could you teach on how to drop the object ?? really appreciate it cause might help me in my fyp

    • @GunzzYT
      @GunzzYT  10 місяців тому

      Here ya go ua-cam.com/video/V9VbwpsvmZo/v-deo.htmlsi=hbQDHqyHOAsWVa7_

  • @hidings
    @hidings Рік тому

    Great tutorial, thanks!

  • @dikshantverma680
    @dikshantverma680 5 місяців тому

    I've picked it up, now how to drop it, mannnn

  • @ACtudio001
    @ACtudio001 Рік тому

    You are the best Thanks you very much!

  • @mohamedrabi3928
    @mohamedrabi3928 Рік тому

    great work

  • @ghostarda6355
    @ghostarda6355 Рік тому

    hi great tutorial! but i want the items to be in the inventory of the player, how do i do it?

    • @GunzzYT
      @GunzzYT  Рік тому

      Thanks, stay tuned i might make an inventory system tutorial soon.

    • @ghostarda6355
      @ghostarda6355 Рік тому

      @@GunzzYT wow this was a fast reply and thx

  • @ROUGETHEBAT456
    @ROUGETHEBAT456 Рік тому

    Do u have the script for pickup flashlight 🔦

  • @akunrandom730
    @akunrandom730 2 місяці тому

    the Flashlight is gone after i pick Up it

  • @lonk199
    @lonk199 Рік тому +1

    i smell nederlands (good tutorial)

    • @GunzzYT
      @GunzzYT  Рік тому

      Very good gevonden 😂

  • @tormipuvi4703
    @tormipuvi4703 Рік тому

    How do I drop it?

  • @mediamermaid333
    @mediamermaid333 Рік тому

    Thank you!!

  • @drake_eric9799
    @drake_eric9799 2 місяці тому

    is working just click the box collider is trigger in flash light use starter asset and i use axe object i think this is the basic next to annimation rigging thnx hahahaha

  • @alisharafeddine3259
    @alisharafeddine3259 Рік тому +1

    why did you do a pick up video without showing how to drop it xd

    • @GunzzYT
      @GunzzYT  Рік тому

      Srry boss ill make a video about that a soon as possible. Pls forgive me 🥺

  • @alexplaytop
    @alexplaytop Рік тому

    I got like this problem: "Internal: Stack allocator ALLOC_TEMP_MAIN has unfreed allocations, size 3565014". Any thoughts???😊

  • @petarashmalaj
    @petarashmalaj Рік тому

    Thanks man

  • @JunaBot
    @JunaBot Рік тому

    version mobile?

  • @mr-maschi
    @mr-maschi 5 місяців тому

    Event though it works, this is absolutely not how you. do it!

  • @JuicyGTT
    @JuicyGTT 8 місяців тому

    Can u send Code?

    • @TVmations
      @TVmations 2 місяці тому +1

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class PickUpFlashlight : MonoBehaviour
      {

      public GameObject FlashLightOnPlayer;
      void Start()
      {
      FlashLightOnPlayer.SetActive(false);
      }
      private void onTriggerStay(Collider other)
      {
      if(other.gameObject.tag -- "Player")
      {
      if (Input.GetKey(KeyCode.E))
      {
      this.gameObject.SetActive(false);
      FlashLightOnPlayer.SetActive(true);
      }
      }
      }
      }

  • @avi-yd6ub
    @avi-yd6ub 5 місяців тому

    packup and drop

  • @madduckling4436
    @madduckling4436 Рік тому

    your tutorial is great sadly one thing I have an issue with , the method you're using will make the player pick up the flashlight regardless of where the player is looking...

    • @GunzzYT
      @GunzzYT  Рік тому

      Its a basic tutorial, you can use a raycast to check wether the item/object your looking at can be interacted with.

  • @not_b4llistick1d
    @not_b4llistick1d Рік тому

    Thank You!