How To Pick Up an Item - Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ส.ค. 2024
  • Subscribe & Like for more Content like this.
    -------------------------------------------------------------
    TH-cam : / gunzzyt
    twitch : / gunzz___
    FlashLight: assetstore.uni...
    FPS Controller: assetstore.uni...

ความคิดเห็น • 79

  • @NoobManBeast
    @NoobManBeast หลายเดือนก่อน +10

    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);
    }
    }
    }

    • @marcysm
      @marcysm วันที่ผ่านมา

      tysm bro

  • @its_nuked
    @its_nuked 5 หลายเดือนก่อน +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

  • @martjaspersalazar2258
    @martjaspersalazar2258 ปีที่แล้ว +8

    Your tutorial is really works my friend. Thank you!

    • @GunzzYT
      @GunzzYT  ปีที่แล้ว

      You're welcome, im glad it helpt

  • @alexplaytop
    @alexplaytop 5 หลายเดือนก่อน +4

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

  • @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 🙏 ❤❤

  • @WARRIORGUY_YT4789
    @WARRIORGUY_YT4789 8 วันที่ผ่านมา

    Thank you so much that worked my friend!🎉

  • @user-fn3tw1nj3e
    @user-fn3tw1nj3e 9 หลายเดือนก่อน +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?

  • @Ambersow
    @Ambersow 2 หลายเดือนก่อน

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

  • @t.sandwich
    @t.sandwich 5 หลายเดือนก่อน +1

    Dude this is so helpful, thank you :)

  • @StoCazzoTanto_non_uso
    @StoCazzoTanto_non_uso 5 หลายเดือนก่อน

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

    • @GunzzYT
      @GunzzYT  5 หลายเดือนก่อน

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

  • @laetusbeats
    @laetusbeats 8 หลายเดือนก่อน

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

  • @adammland6924
    @adammland6924 5 หลายเดือนก่อน +1

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

  • @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

  • @johnlouisedelacruz8905
    @johnlouisedelacruz8905 ปีที่แล้ว +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  ปีที่แล้ว +1

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

  • @YusafAnimations
    @YusafAnimations ปีที่แล้ว

    bro that is genius imma test this tomorrow

  • @lonk199
    @lonk199 ปีที่แล้ว +1

    i smell nederlands (good tutorial)

    • @GunzzYT
      @GunzzYT  ปีที่แล้ว

      Very good gevonden 😂

  • @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

  • @hidings
    @hidings ปีที่แล้ว

    Great tutorial, thanks!

  • @onlyrxtro7059
    @onlyrxtro7059 หลายเดือนก่อน +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  หลายเดือนก่อน +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")

  • @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

  • @mohamedrabi3928
    @mohamedrabi3928 ปีที่แล้ว

    great work

  • @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 6 หลายเดือนก่อน

    YOUR TUTORIAL ARE REALLY HELPFUL THANKS FOR UPLOADING

  • @ACtudio001
    @ACtudio001 ปีที่แล้ว

    You are the best Thanks you very much!

  • @hh5559
    @hh5559 8 หลายเดือนก่อน

    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

  • @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

  • @dikshantverma680
    @dikshantverma680 3 หลายเดือนก่อน

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

  • @GMlife317
    @GMlife317 7 หลายเดือนก่อน

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

  • @drake_eric9799
    @drake_eric9799 25 วันที่ผ่านมา

    how to drop the flash light

  • @yourexorcist4436
    @yourexorcist4436 7 หลายเดือนก่อน

    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  7 หลายเดือนก่อน +1

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

  • @drake_eric9799
    @drake_eric9799 25 วันที่ผ่านมา

    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

  • @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!

  • @mediamermaid333
    @mediamermaid333 ปีที่แล้ว

    Thank you!!

  • @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?

    • @ROISZ_Editz
      @ROISZ_Editz 11 หลายเดือนก่อน

      Chat_GPTcan do that

  • @b4llistick1dYT
    @b4llistick1dYT ปีที่แล้ว

    Thank You!

  • @RadioTelevizijaPrijecani
    @RadioTelevizijaPrijecani ปีที่แล้ว

    Thanks man

  • @saadstj7147
    @saadstj7147 ปีที่แล้ว

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

  • @malachipeck7450
    @malachipeck7450 ปีที่แล้ว

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

  • @haeqallz19
    @haeqallz19 8 หลายเดือนก่อน

    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  8 หลายเดือนก่อน

      Here ya go th-cam.com/video/V9VbwpsvmZo/w-d-xo.htmlsi=hbQDHqyHOAsWVa7_

  • @Ganiovi
    @Ganiovi 8 หลายเดือนก่อน

    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 6 หลายเดือนก่อน

    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

  • @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"

  • @akunrandom730
    @akunrandom730 3 วันที่ผ่านมา

    the Flashlight is gone after i pick Up it

  • @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

  • @avi-yd6ub
    @avi-yd6ub 4 หลายเดือนก่อน

    packup and drop

  • @user-gb6fk5rz1z
    @user-gb6fk5rz1z 7 หลายเดือนก่อน

    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  7 หลายเดือนก่อน

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

    • @user-gb6fk5rz1z
      @user-gb6fk5rz1z 7 หลายเดือนก่อน

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

  • @ROUGETHEBAT456
    @ROUGETHEBAT456 ปีที่แล้ว

    Do u have the script for pickup flashlight 🔦

  • @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 🥺

  • @tormipuvi4703
    @tormipuvi4703 ปีที่แล้ว

    How do I drop it?

  • @mr-maschi
    @mr-maschi 3 หลายเดือนก่อน

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

  • @JunaBot
    @JunaBot 10 หลายเดือนก่อน

    version mobile?

  • @YepJuicYT
    @YepJuicYT 6 หลายเดือนก่อน

    Can u send Code?

    • @TVmations
      @TVmations 6 วันที่ผ่านมา +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 ปีที่แล้ว

    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.

  • @alexplaytop
    @alexplaytop ปีที่แล้ว

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