it took me 30 minutes but i figured out that the script wasnt working because i forgot to put an exclamation mark in one spot, thanks for the tutorial
@ophiliex2 жыл бұрын
That was exactly what I was looking for, thank you very much! Super helpful video!
@DanPos2 жыл бұрын
No worries!
@Dehakuzo2 жыл бұрын
The info on the Interface helped a lot, and I had no idea about the 2d sprite scale limits, thanks for the info!
@DanPos2 жыл бұрын
Happy to help! Glad you found the video useful :D
@Revlos2 ай бұрын
I'm very new to unity but this was a super easy to follow and extremely useful tutorial. I wish you would have explained things abit better in some parts. I was just listening to you say "interactor" a bunch of times and was getting confused. But after you started linking things together in unity it started to make sense. Thanks so much for this, liked and subbed!
@DanPos2 ай бұрын
Glad you enjoyed it!
@lukakhvitia3797 Жыл бұрын
This lecture is the best example to understand Interfaces, thank you for your work!!!
@DanPos Жыл бұрын
You're very welcome!
@Theran_1 Жыл бұрын
You deserve teh world my boy, ty so much, also try not to rush so much towards teh end, still, God Video
@GemGameDev Жыл бұрын
Thanks for this tutorial. Hope you bring out more and more of these it is insane to have open access on learning footage like yours. btw I lost like 20 minutes bc of an error in an if statement I did'nt understand. The solution was that I wrote íf with an í instead of an i lol. I love coding p.p
@rockeeb8 ай бұрын
Thank you so much for this! I was having problems with the UI not closing after getting away from the "chest" and I replayed the video for 4-5 times. Finally solved it with switching if/else positions of _numFound > 0. I don't know what was causing the issue, the script simply doesn't disable the UI when it's at the bottom of "if". Maybe it doesn't make sense, i don't know. I've been trying to do this for about 3-4 hours. Thanks again!
@racrity8 ай бұрын
Awesome tutorial! Really thankful for this
@DanPos8 ай бұрын
You're very welcome!
@rebornl2 жыл бұрын
Great Tutorial! Easy to follow.
@Templaricus10 ай бұрын
on my interactable script in the playerArmature, none of the other options show up, except from something that says script, and interactor
@zombiekriz68412 жыл бұрын
Hey so on 9:32 it doesn't recognize the Interactor and says "type or namespace name 'Interactor' could not be found" and I don't know what I did wrong
@DanPos2 жыл бұрын
Double check your spelling of the namespace and your reference to the name space
@zombiekriz68412 жыл бұрын
@@DanPos I spelled everything correctly
@DanPos2 жыл бұрын
@@zombiekriz6841 can you join the discord and share your scripts?
@zombiekriz68412 жыл бұрын
@@DanPos ok
@MachiavellianPenguin12342 жыл бұрын
@@DanPos I am also running into this issue. Did you two find the solution to the problem?
@512Squared2 жыл бұрын
Dan - zoom in to your code please, we don't need to see the project folder. Could barely read it. EDIT: you zoomed in 😂😘
@DanPos2 жыл бұрын
Haha yeah was going to say! Its something I'm trying to remember to do more
@splitticai Жыл бұрын
Thanks for helping me with this
@DanPos Жыл бұрын
Any time!
@Ray-Dolito2 жыл бұрын
Dude, thank you so much, I was looking for how to do precisely this for a while. I have a doubt about the Collider's array though, will the value in [0] return the first object to enter the overlap sphere? or will it give back the closest to the center of the sphere? And if it's the first one, is there any way of grabbing the closest collider to the player first? I'm using quite a big area of interaction. Again thanks, and please keep making content like this ❤
@DanPos2 жыл бұрын
My feeling is it will be the first to enter, you would need to loop over each element in the array and test distance to that object and choose the smallest one if you want to do that
@Ray-Dolito2 жыл бұрын
@@DanPos I'll give it a try, thanks ;)
@maximeumbra72352 жыл бұрын
If you went with comparing distances, make sure you compare squared distances and not the actual distances with something like Vector3.Distance
@onemangamer587 Жыл бұрын
@@maximeumbra7235 Why?
@diggerpy Жыл бұрын
@@onemangamer587 probably more optimized
@ccohn0 Жыл бұрын
Everything works except that something deletes whatever text I had in the text box when the prompt is supposed to load. The image shows up, but the text doesn't and the textbox instantly becomes empty.
@nielshenriksen10432 жыл бұрын
thank you for this video.... I need to see what else you have :)
@DanPos2 жыл бұрын
You're so welcome!
@TheJokerCard21 Жыл бұрын
I have a problem that when I interact with the mech as a player to enter in it firstly works but then if I go down from the mech pressing E and then try to go in again it will not work, it will not even show in console that o hit something with the raycast...
@micol04 Жыл бұрын
im trying to make the e button work with a gamepad button. but its not working. my input manager is set up and so is player input. please what do i need to do to achieve this
@AlessandraROlaya Жыл бұрын
Thank u so much!
@orsettolavatore84352 жыл бұрын
Thank you for the tutorial! Could you explain me why you made serialized fields in interactor class? Is something we should save?
@celinedrules2 жыл бұрын
He does it this way so he can keep the variables private but can change the values in the inspector. It is better than making them public.
@Calavera0010 ай бұрын
Great tutorial! I would like the prompt and interaction icon in the world over the asset to interact with instead of over the player. I could create a prefab and place on assets, but I can't get it to work with this setup where a single UI canvas needs to be attached to the Interaction prompt UI on the player. Does anyone have a suggestion for how to achieve this?
@DanPos10 ай бұрын
You can still have the single canvas attached to the player but set it's position every time you make it appear to that of the object with some sort of offset. That would be the simplest way.
@sebastianmarrera1822 Жыл бұрын
how can i make a prompt only appears if a chest hasnt been looted, but then, after interact, theres no more prompt?
@DanPos Жыл бұрын
Once the chest is looted disable it's interact script
@wickedlich2 жыл бұрын
It sounds like you have an alarm going off in the background and it is driving me insane.
@adammaxwell9898 Жыл бұрын
So I'm following this tutorial and after i saved the interactor script and when i came back to the scene, there was an error saying Assets/Scripts/Interactor.cs(17,97): error CS1003: Syntax error, ',' expected, what should I do?
@DanPos Жыл бұрын
It's telling you there, it's expecting a comma. Double click the error in the console and it will take you to the line you've typed some
@adammaxwell9898 Жыл бұрын
@@DanPos ok thank you
@MoonGluedStudios Жыл бұрын
I've watched this so many times and I cant figure out why I keep getting an error on the line promptText.text = promptText; The error message says "'string' does not contain a definition for 'text' and no accessible extension method 'text' accepting a first argument of type 'string' could be found" Please help!
@DanPos Жыл бұрын
Looks like you've forgotten the underscore for the first part _promptText.text
@MoonGluedStudios Жыл бұрын
@@DanPos that did it! dang I feel dumb but thank you and thank you for the tutorial!
@DanPos Жыл бұрын
@@MoonGluedStudios tbf that's poor naming conventions on my part!
@GemGameDev Жыл бұрын
i had the same prob, never feel dumb bc of simple typos bruh
@SGUDevs9 ай бұрын
instead of layermask couldn't we do collider?
@leerc772111 ай бұрын
How can I get a reference to the exact object that was interacted with in the child class? Currently trying to raise an event on a pickup item that was interacted with so that I can handle the pickup event.
@DanPos11 ай бұрын
If you just want the game object then when you are looking for the interact interface then you can get the reference at the same time. If you want the specific class then you will just need to check for it then too, or on that class you could have a unity event like OnItemPickUp that you listen out for wherever you need to know about that
@TheRyanSmee2 жыл бұрын
Hi, I was wondering if there is a way of detecting when items are removed from the _colliders array? I'm using QuickOutline to highlight the focused item but I cant think of a good way to remove the outline when the player moves away
@TheRyanSmee2 жыл бұрын
Brilliant video btw!
@onemangamer587 Жыл бұрын
I suppose you could do one of two things: 1 - Loop over the items in the array then check to see if they are still in the array after the array length changes. If they are, keep the outline, if they aren't, remove the outline. 2 - Store the same items in another array and keep comparing between the collision array and the new compare array. Once an item is no longer in the collision array, you can remove it from the compare array and remove the outline. It's crude but I guess it could work. Hope this helps.
@jaggro172 жыл бұрын
is this also an ideal way to set up an object to pickup and drop?
@normanbates31102 жыл бұрын
Thanks that's nice and clear ! How can i apply the canvas to an object instead of the player ? So the prompt appear on the object when you are walking close to it. Thanks !
@DanPos2 жыл бұрын
You could either give each object the canvas prefab or just set the prefab to the location of the Interactable object
@GemGameDev Жыл бұрын
@@DanPos thanks! had the same question, this really helped
@Bourbonbteam Жыл бұрын
Hi, im running into an issue at 26:55 . I keep on getting Error CS1513 when i have the exact same code as the tutorial, i dont get how this error is being created. i have no idea how this is being caused when i have the exact same code as the tutorial
@DanPos Жыл бұрын
Can you paste your code below?
@Bourbonbteam Жыл бұрын
@@DanPos ended up putting the issue into ChatGPT and found a solution with that. Wasnt a missing } it just didnt like the code for some reason
@BLACKDREAMIO Жыл бұрын
can you please zoom the code editor because its too small i can hardy see your code i have to leave
@dunderguy2 жыл бұрын
You are literally my only hope before I give up on this mechanic I have tried everything and nothing works. This is my problem. Assets\IInteractable.cs(8,15): error CS0501: 'IInteractable.Interact(Interactor)' must declare a body because it is not marked abstract, extern, or partial. This is the IInteractable code using System.Collections; using System.Collections.Generic; using UnityEngine; public class IInteractable : MonoBehaviour { public string InteractionPrompt { get; } public bool Interact(Interactor interactor); } ____________________________ This is the Interactor code. _____________________________ using System.Collections; using System.Collections.Generic; using UnityEngine; public class Interactor : MonoBehaviour { [SerializeField] private Transform _interactionPoint; [SerializeField] private float _interactionPointRadius = 0.5f; [SerializeField] private LayerMask _interactableMask; private readonly Collider[] _colliders = new Collider[3]; [SerializeField] private int _numFound; private void Update() { _numFound = Physics.OverlapSphereNonAlloc(_interactionPoint.position, _interactionPointRadius, _colliders, _interactableMask); } private void OnDrawGizmos() { Gizmos.color = Color.red; Gizmos.DrawWireSphere(_interactionPoint.position, _interactionPointRadius); } }
@DanPos2 жыл бұрын
Your IInteractable shouldn't inherit from monobehaviour, it's an interface
@dunderguy2 жыл бұрын
@@DanPos Thank you so much
@kimberlyramgopal2391 Жыл бұрын
I followed the video correctly up until 32:50 my InteractionPromptUI Script is identical and in the inspector, I added all the components but when I walk up to an object the UI does not show. I have to physically check the IsDisplayed box in the inspector to get the UIs to show. Is there any way to fix this?
@lachlanpott7484 Жыл бұрын
I am having the same problem aswell
@nuclearchicken5494 Жыл бұрын
add _interactionPromptUI.isDisplayed = true; after if(_numFound >0)
@mahersabit9265 Жыл бұрын
quick question, whats the difference between using public and using serialized field?
@DanPos Жыл бұрын
If it was public other scripts would be able to access it, serialize field allows you to just access it from the inspector to set variables
@happy5468 Жыл бұрын
hey, what is the script writing software u are using, ive seen it on many creators and its much more advanced then visual studio. Id really like to get that one. edit: I found one, is it JetRider? but it seems thats its not free, only 30 day trial, if i download the one for unity only is that one completely free?
@DanPos Жыл бұрын
Yeah it's Rider and no it's not free unfortunately but definitely worth the price if you can afford it
@jessboles2 жыл бұрын
Hi! Great video. I'm trying to make an interaction system in a 2D game, however to use your tutorial work I need box colliders instead of 2D box colliders, or it won't work. Is there something I can adjust in the code to keep using 2D box colliders? Thanks!
@DanPos2 жыл бұрын
You should be able to just swap any mention of 3d colliders to their 2d counterparts, for example overlap circle 2d docs.unity3d.com/ScriptReference/Physics2D.OverlapCircle.html
@jessboles2 жыл бұрын
@@DanPos Wow, thanks for the speedy reply! It works great :)
@TheKr0ckeR2 жыл бұрын
How would i do smth like, instead of clicking E, we have to hold it. What approach would you go on that way?
@DanPos2 жыл бұрын
You can do two things, one using the new input system the other using either input systems. Using new input system, you can add a Hold processor to the input action map which means the button will only trigger once it's held long enough. Using either input system, create two floats on your interactor script, one called Hold time the other called current time. Set hold time to however long you want the player to the hold the button for, and I stead of using WasPressedThisFrame you can check in update if it's currently held down. If it is add Time.deltaTime to the current time float you made. Then you can use an if statement to check if current time is greater than hold time, if it is you can then interact with the Interactable object
@arifzikri0902 Жыл бұрын
Hey Dan! is the serializefield necessary? Can't I just use private? thanks in advance
@DanPos Жыл бұрын
Not sure which line you're referring too but if you want to see something in the inspector/set it in the inspector you will need serializefield or for it to be public. Any other instance you can just use private.
@lukasz.akozlowski2832 Жыл бұрын
can anyone help me im getting lots of CS0246 and im unsure why
@Jimpmm11 ай бұрын
It say Physics does not contain a definition for OverLapSphereNonAlloc
@DanPos11 ай бұрын
You've put a capital L in Overlap
@OhMyShad2 жыл бұрын
I dont know why but when I come close to the cube it shows no Text on it :C
@DanPos2 жыл бұрын
Join the Discord and will see if I can help - its linked in the description of this video. Off the top of my head, you've probably forgot to assign the string from the interaction to the actual text ui
@michaelwilson84612 жыл бұрын
So would it be wrong to think of interfaces as just classes with virtual functions that have to be implemented in any class that sub-classes it ? Or is there a fundamental difference that I need to consider ?
@r6scrubs1262 жыл бұрын
interfaces are literally just a "contract" saying if any class implements this interface, it must implement these functions with these specific parameters and return type etc. That's it. No need to over complicate it by comparing them to classes and inheritance etc
@maximeumbra72352 жыл бұрын
Interfaces can have both abstract and virtual members. Conceptually it is as others said a contract that this object will at a minimum contain the things the interface lists whether it is via default body or virtual overrides, they are guaranteed to exist.
@cweep794 Жыл бұрын
why do yu write an _ before every variable?
@DanPos Жыл бұрын
Its Unity coding standards, the _ indicates a private global level variable
@cweep794 Жыл бұрын
@@DanPos thanks
@Dehakuzo2 жыл бұрын
10:35 Something I've been trying to figure out since I picked up Unity... Does it crash regularly? After all, this is a completely new project from the looks of it. Some days it feels like it crashes dozens of times, other times it'll last multiple days with no issue. I was stressed out like hell thinking I imported a bad asset or something but ended up giving up and dealing with the crashes... till they softened out on their own. Also, any way to figure out WHY it actually crashed?
@DanPos2 жыл бұрын
I'm not sure how to figure out WHY it crashed, there is probably a log somewhere, as for the frequency of them, I never really had Unity crashes until the latest versions of 2020 LTS, I've been using 2020 LTS for a while and its been mostly very stable and would only really crash if it got stuck in an infinite loop. I've been experience a lot more crashes recently though!
@MichaelSchubertPhoto2 жыл бұрын
I'm searching to trigger a UI Element in Worldspace (e.g. Button with my Mouse (Canvas crosshair in the middle)) while beeing in FPS or 3rd Person view. Anybody has a solution? Do I need to use a Physical Raycaster? Ideally using the New Input System
@onemangamer587 Жыл бұрын
Do you mean to do the same thing as in the tutorial but in first person? If so, all I did was pair the canvas to the camera, and then to avoid the UI elements from clipping through the walls, you can just render them on another camera that is only used for rendering UI elements, so it's drawn over everything else.
@MichaelSchubertPhoto Жыл бұрын
@@onemangamer587 thank you
@onemangamer587 Жыл бұрын
@@MichaelSchubertPhoto No problem. Your initial comment was 8 months ago, how's the project getting along? Any progress?
@LilDrowzee2 жыл бұрын
Could anyone make this without using UnityEngine.InputSystem?
@onemangamer587 Жыл бұрын
What do you mean exactly? Are you referring to the new Input system? Or just the Input system in general?
@wormholeinteractive2 жыл бұрын
Hi there! New subscriber and total noob. I am experiencing the following - I created both scripts for the door and chest but for some reason, only the door seems to be working (in terms of the Debug line, and the collision detection) - I erased my chest script, copy + pasted the code from the door script, and still not working? Is there something that could be preventing both scripts from working simultaneously? Any suggestions would be great!
@DanPos2 жыл бұрын
If you use Discord you could join the discord server in the description and share your code and I could take a look. The other thing if you've copied code, make sure the class name matches the file name, make sure you door and chest are both on the Interactable layer, make sure there is a collider attached to the top level object. Hopefully some of those tips help!
@onemangamer587 Жыл бұрын
If the code is identical (minus the text in the debug.log), then chances are you didn't add the Interactable layer to the Chest Game Object in the Inspector, In the top right corner next to "Layer" dropdown menu. Hope this helps.
@LIZI_Neazle Жыл бұрын
great
@YellowLimes2 жыл бұрын
does this only work with 3d?
@funkynormalcat9888 ай бұрын
increase the size of the text please
@folgoll89272 жыл бұрын
This video was helpful, however I think out of courtesy I should tell you that I believe your teaching style here with this video is not very good for people who are trying to learn unity. The main problem comes from the coding. When you talk us through your code you seem to just reword what the code says rather than explain what the code is doing or why it works. I notice this a lot with Unity tutorials. This would be okay if we were writing a single program, however Unity is very complex and if the people using this code don't understand how or why it works than it will be very difficult for them to try and add onto, or debug their code. I am a CS major and had absolutely no idea what was going on here(admittedly I haven't learned C# yet), I would have learned just as much if you had just given me the scripts. Now, the video is great, and I really love what you are doing here, but please, in future videos try to explain how and why the code works
@DanPos2 жыл бұрын
Thanks for the feedback and you raise some valid points, however to stop and explain every point on a basic level would make the video very long and risk boring anyone who is just coming out of the beginner phase. For complete beginners I'd never recommend my videos or any KZbin videos are a first point of call, I'd always suggest a structured course first such as the GameDev.tv one which will give people the prerequisite knowledge to hopefully follow along with this style of teaching
@BlooshedDeveloper2 жыл бұрын
what is that F button icon name in your thumbnail?
@DanPos2 жыл бұрын
thoseawesomeguys.com/prompts/
@BlooshedDeveloper2 жыл бұрын
@@DanPos TYSM
@imviciously2 жыл бұрын
Ive done everything the same but the image doesnt hide although the num found goes back to 0
@DanPos2 жыл бұрын
Double check again as you will have missed something - easily done! If you want you can join the discord linked in the description and send me your script and I can take a look
@imviciously2 жыл бұрын
@@DanPos ok i sent my code on the discord server
@sarahpuspdew2 жыл бұрын
@@imviciously i have the same problem...can u help me
@bexymathew96682 жыл бұрын
Pls reply
@DanPos2 жыл бұрын
To what?
@lefoudegaming1233 Жыл бұрын
Thank you to make me discover the variant of "Input.GetKeyDown(KeyCode.E)" for the New Input System (Keyboard.current.eKey.wasPressedThisFrame) What is the method for Playstation Controller ? PlayStationController.current.Triangle.wasPressedThisFrame ????? Gamepad.Playsation.current.Triangle.wasPressedThisFrame ????