How To Pick Up an Item - Unity

Sdílet
Vložit
  • čas přidán 13. 09. 2024
  • Subscribe & Like for more Content like this.
    -------------------------------------------------------------
    CZcams : / gunzzyt
    twitch : / gunzz___
    FlashLight: assetstore.uni...
    FPS Controller: assetstore.uni...

Komentáře • 81

  • @NoobManBeast
    @NoobManBeast Před měsícem +12

    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 Před 6 měsíci +5

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

  • @martjaspersalazar2258
    @martjaspersalazar2258 Před rokem +8

    Your tutorial is really works my friend. Thank you!

    • @GunzzYT
      @GunzzYT  Před rokem

      You're welcome, im glad it helpt

  • @Infinity-nw1jt
    @Infinity-nw1jt Před rokem +3

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

  • @francescogamba1301
    @francescogamba1301 Před rokem +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

  • @hamzaShahid-x5i
    @hamzaShahid-x5i Před 10 měsíci +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 Před 6 měsíci +4

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

  • @Ambersow
    @Ambersow Před 3 měsíci

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

  • @t.sandwich
    @t.sandwich Před 6 měsíci +1

    Dude this is so helpful, thank you :)

  • @WARRIORGUY_YT4789
    @WARRIORGUY_YT4789 Před 28 dny

    Thank you so much that worked my friend!🎉

  • @adammland6924
    @adammland6924 Před 6 měsíci +1

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

  • @StoCazzoTanto_non_uso
    @StoCazzoTanto_non_uso Před 5 měsíci

    TI ADORO, SEI IL MIO SALVATORE. NON TROVAVO VIDEO CON IL TASTO "E" PER RACCOGLIERE GLI OGGETTI (traduce to english)

    • @GunzzYT
      @GunzzYT  Před 5 měsíci

      Ik hou ook heel veel van jouw! graag gedaan. (translate to english)

  • @laetusbeats
    @laetusbeats Před 9 měsíci

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

  • @beefytime1374
    @beefytime1374 Před rokem

    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

  • @johnlouisedelacruz8905
    @johnlouisedelacruz8905 Před rokem +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  Před rokem +1

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

  • @emeraldwas9k
    @emeraldwas9k Před rokem

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

  • @REBELHEADGAMES
    @REBELHEADGAMES Před rokem +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 Před rokem

      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

  • @YusafAnimations
    @YusafAnimations Před rokem

    bro that is genius imma test this tomorrow

  • @DaDylanMachine
    @DaDylanMachine Před rokem +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  Před rokem +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 Před rokem

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

  • @hidings
    @hidings Před rokem

    Great tutorial, thanks!

  • @ACtudio001
    @ACtudio001 Před rokem

    You are the best Thanks you very much!

  • @galberger3937
    @galberger3937 Před rokem +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?

  • @hh5559
    @hh5559 Před 8 měsíci

    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

  • @onlyrxtro7059
    @onlyrxtro7059 Před 2 měsíci +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  Před 2 měsíci +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")

  • @abdeali5341
    @abdeali5341 Před 7 měsíci

    YOUR TUTORIAL ARE REALLY HELPFUL THANKS FOR UPLOADING

  • @mohamedrabi3928
    @mohamedrabi3928 Před rokem

    great work

  • @lonk199
    @lonk199 Před rokem +1

    i smell nederlands (good tutorial)

    • @GunzzYT
      @GunzzYT  Před rokem

      Very good gevonden 😂

  • @RevibeMods
    @RevibeMods Před 2 dny

    how could i make it so Q drops the object?

  • @drake_eric9799
    @drake_eric9799 Před měsícem

    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

  • @parthacodes5893
    @parthacodes5893 Před rokem

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

  • @GMlife317
    @GMlife317 Před 8 měsíci

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

  • @dikshantverma680
    @dikshantverma680 Před 4 měsíci

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

  • @yourexorcist4436
    @yourexorcist4436 Před 8 měsíci

    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  Před 8 měsíci +1

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

  • @Ganiovi
    @Ganiovi Před 9 měsíci

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

  • @lfigure1718
    @lfigure1718 Před rokem +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  Před rokem

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

    • @lfigure1718
      @lfigure1718 Před rokem

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

  • @b4llistick1dYT
    @b4llistick1dYT Před rokem

    Thank You!

  • @Un_tizio1
    @Un_tizio1 Před 7 měsíci

    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

  • @RadioTelevizijaPrijecani

    Thanks man

  • @haeqallz19
    @haeqallz19 Před 9 měsíci

    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  Před 9 měsíci

      Here ya go czcams.com/video/V9VbwpsvmZo/video.htmlsi=hbQDHqyHOAsWVa7_

  • @malachipeck7450
    @malachipeck7450 Před rokem

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

  • @drake_eric9799
    @drake_eric9799 Před měsícem

    how to drop the flash light

  • @saadstj7147
    @saadstj7147 Před rokem

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

  • @Tricksy_2014
    @Tricksy_2014 Před rokem +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 Před rokem

    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"

  • @user-gb6fk5rz1z
    @user-gb6fk5rz1z Před 8 měsíci

    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  Před 8 měsíci

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

    • @user-gb6fk5rz1z
      @user-gb6fk5rz1z Před 8 měsíci

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

  • @ghostarda6355
    @ghostarda6355 Před rokem

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

    • @GunzzYT
      @GunzzYT  Před rokem

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

    • @ghostarda6355
      @ghostarda6355 Před rokem

      @@GunzzYT wow this was a fast reply and thx

  • @ROUGETHEBAT456
    @ROUGETHEBAT456 Před rokem

    Do u have the script for pickup flashlight 🔦

  • @akunrandom730
    @akunrandom730 Před 22 dny

    the Flashlight is gone after i pick Up it

  • @alisharafeddine3259
    @alisharafeddine3259 Před rokem +1

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

    • @GunzzYT
      @GunzzYT  Před rokem

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

  • @avi-yd6ub
    @avi-yd6ub Před 4 měsíci

    packup and drop

  • @tormipuvi4703
    @tormipuvi4703 Před rokem

    How do I drop it?

  • @JunaBot
    @JunaBot Před 11 měsíci

    version mobile?

  • @mr-maschi
    @mr-maschi Před 4 měsíci

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

  • @YepJuicYT
    @YepJuicYT Před 7 měsíci

    Can u send Code?

    • @TVmations
      @TVmations Před 26 dny +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);
      }
      }
      }
      }

  • @madduckling4436
    @madduckling4436 Před rokem

    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  Před rokem

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

  • @alexplaytop
    @alexplaytop Před rokem

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

  • @mediamermaid333
    @mediamermaid333 Před rokem

    Thank you!!