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...
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);
}
}
}
tysm bro
TYSM
thank you for the script
Felt on the family interrupt and the jet/text outline was funny xDDD
Ty man :D
If you are having issues with the pickup part just add a rigid body to the battery and disable gravity, everything should work correctly
I could not figure this out before and now that I saw that video I want to thank you so much 🙏 ❤❤
does not seem to be working for me, can I get some help. the code is not allowing me to pick up the torch?
Would be cool to explain how to drop it, after pick up ))
Your tutorial is really works my friend. Thank you!
You're welcome, im glad it helpt
thx its very helpful thx very much ... thanks Gunzz very cool . i subbed and liked btw
Dude this is so helpful, thank you :)
So helpful and very easy to follow! Keep it up!
Is there any chance you can make it that you can ONLY TOGGLE it on and off when you are holding it? Kind regards.
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
thank you so much for your tutorial and it really works!!
Do you also have a video on how to drop items?
You're welcome, maybe i will make a drop system in the near future stay tuned 😁
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
this is really easy thank you and you kinda got me scared at the end lol
Thank you so much that worked my friend!🎉
ik ruik een beetje Nederlands, dankjewel btw je hebt me echt geholpen!
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.
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.
@GunzzYT got it, good to know. Thanks for responding
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
how could i make it so Q drops the object?
umm for me i dont need to press E its just as soon as you get in the range it gets on your hand
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?
YOUR TUTORIAL ARE REALLY HELPFUL THANKS FOR UPLOADING
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?
make sure there are no errors and make the Variables Public not private.
@@GunzzYT Got it fixed, turns out there was a bug completely destroying our code but we manage to fix it. Thank you!
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
Give your controller the tag MainPlayer and others just Player, then change the tag check in the ontriggerenter to -> if(other.gameObject.tag == "MainPlayer")
can we use this method to add multiple items to our player and to pick each one at the different time ?
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
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.
Child it under your Main Camera, that should do the trick.
bro that is genius imma test this tomorrow
what are you doing here?
can you make a tut on inventory?
i found you on a random video again
Whenever I try to drag a gameobject to the script it wont let me do it with any objects
op now i wil implement my own thing like change it to a key and then also make that key trigger doors and chests
has anyone modified the skript so that you can pick up and drop ?
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?
Make sure isTrigger is selected on the boxcollider! if its not your player cannot enter the trigger.
@@GunzzYT Yes! That was the issue, thanks you so much, I'm new to unity. Great video by the way!
how to drop the flash light
This works just for one item. I tried to pick up more than one item it is not working.
With the OnTriggerExit part, it does not work for me. Once I enter, the text stays there. Does anyone have a fix for this?
Chat_GPTcan do that
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"
bro if you dont mind, could you teach on how to drop the object ?? really appreciate it cause might help me in my fyp
Here ya go ua-cam.com/video/V9VbwpsvmZo/v-deo.htmlsi=hbQDHqyHOAsWVa7_
Great tutorial, thanks!
I've picked it up, now how to drop it, mannnn
You are the best Thanks you very much!
great work
hi great tutorial! but i want the items to be in the inventory of the player, how do i do it?
Thanks, stay tuned i might make an inventory system tutorial soon.
@@GunzzYT wow this was a fast reply and thx
Do u have the script for pickup flashlight 🔦
the Flashlight is gone after i pick Up it
sorry it works
i smell nederlands (good tutorial)
Very good gevonden 😂
How do I drop it?
Thank you!!
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
why did you do a pick up video without showing how to drop it xd
Srry boss ill make a video about that a soon as possible. Pls forgive me 🥺
I got like this problem: "Internal: Stack allocator ALLOC_TEMP_MAIN has unfreed allocations, size 3565014". Any thoughts???😊
Thanks man
version mobile?
Event though it works, this is absolutely not how you. do it!
Can u send Code?
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);
}
}
}
}
packup and drop
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...
Its a basic tutorial, you can use a raycast to check wether the item/object your looking at can be interacted with.
Thank You!