4 Ways to Interact with Doors in Unity! (Key, Button, Auto, Pressure)

✅ Get the Project files and Utilities at unitycodemonkey.com/video.php...
Let's check out 4 different Methods to Interact with Doors.
These can be abstracted to Interact with any object.
3 Ways to Open Doors in Unity!
• 3 Ways to Open Doors i...
Simple Key Door System in Unity
• Simple Key Door System...
Melee Combat System in Unity 2D!
• Melee Combat System in...
3 Ways to Shoot Projectiles in Unity
• 3 Ways to Shoot Projec...
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
See you next time!
📍 Support on Patreon / unitycodemonkey
🤖 Join the Community Discord / discord
📦 Grab the Game Bundle at unitycodemonkey.com/gameBundl...
📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
#unitytutorial #unity3d #unity2d
--------------------------------------------------------------------
Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Website: unitycodemonkey.com/
- Twitter: / unitycodemonkey
- Facebook: / unitycodemonkey

Пікірлер: 88

  • @CodeMonkeyUnity
    @CodeMonkeyUnity4 жыл бұрын

    Previously we made 3 Doors, now lets look at 4 Methods to Interact with them! You can also make this work for any object type! 🌐 Have you found the videos Helpful and Valuable? ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php

  • @ArjayHD
    @ArjayHD4 жыл бұрын

    Yuss! Just what I needed! Thank you!

  • @havishfun
    @havishfun3 жыл бұрын

    15:10 is pressure plate.

  • @hoo1320
    @hoo13204 жыл бұрын

    great video as always! yeah, my code monkey keep going forward, dude :)

  • @branidev
    @branidev4 жыл бұрын

    love your videos you teach me a lot... i hope i will so much experienced like you!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Thanks! Keep it up and you'll get there!

  • @WhitefoxSpace
    @WhitefoxSpace2 жыл бұрын

    15:15 for the Pressure Plate method

  • @heatherbyrom5940

    @heatherbyrom5940

    2 жыл бұрын

    you're a gem

  • @Oxmond
    @Oxmond4 жыл бұрын

    We looooove doors 👍🤓

  • @RVRGaming
    @RVRGaming4 жыл бұрын

    If anyone wants to have the pressure plate being a on/off toggle (for a button for example). Create a new script and add this (then add it to the pressure plate you made): public class DoorOnOff : MonoBehaviour { [SerializeField] private GameObject doorGameObject; private IDoor door; private bool isOpen = false; private void Awake() { door = doorGameObject.GetComponent(); } private void OnTriggerEnter(Collider collider) { if (collider.gameObject.tag == "OpenAuto") { isOpen = !isOpen; if (isOpen) { door.OpenDoor(); } else { door.CloseDoor(); } } } }

  • @xbun_gamin

    @xbun_gamin

    2 жыл бұрын

    thanks man!

  • @VFORVICTORY1000
    @VFORVICTORY10004 жыл бұрын

    THX tutorial

  • @iconicik4120
    @iconicik41202 жыл бұрын

    ive been learning and getting closer to having a lot of the basics down just im looking at your script on the keys and however i dont need that right now i have it set up for points and killing zombies so far in a wave of them. just not sure if this is the kind of code i should be following to make it into my own per se but any ideas maybe on how to go about it after having the animations for it?

  • @RVRGaming
    @RVRGaming4 жыл бұрын

    Code Monkey, this is amazing stuff! Absolutely loving it! I'm not great with C#, so was wondering what I would need to change to the pressure plate script to have it only close when, when stepping on it again?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    You would store a boolean in your pressure plate, then OnTriggerEnter you would invert it and either open or close. Similar to how the button method uses the same button both for opening and closing.

  • @RVRGaming

    @RVRGaming

    4 жыл бұрын

    @@CodeMonkeyUnity Hey, thanks for the feedback. Ended up working!

  • @AidinZolghadr
    @AidinZolghadr4 жыл бұрын

    I need an FSM system for my game, what would do you recommend? Have you done any tutorials on it? Also your thoughts on using Animator as State Machine for things other than animation.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    I've covered a Simple Enemy AI State Machine kzread.info/dash/bejne/lpZkrbmSkbrMlbA.html I've heard of the animator being used as a state machine but never tried it myself, should work pretty well though.

  • @Drk2cl
    @Drk2cl3 жыл бұрын

    can you make a tutorial for a door that you can use when you open the inventory and select the correct item and there is a choice between inspect and use?

  • @flydiegofly

    @flydiegofly

    3 жыл бұрын

    I'm searching for the same thing! If you've found it, please let me know.

  • @victorgiovannoni
    @victorgiovannoni3 жыл бұрын

    Thanks for the video! Regarding the pressure plate timing mechanism, do you think it is better to use the time variable like you did in the video or use a Coroutine that would be dispatched when exiting the pressure plate?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Personally I dislike Coroutines because of the pattern they force you to use but they achieve the same result so if you like them feel free to use them.

  • @Ahmed-ic9ft
    @Ahmed-ic9ft4 жыл бұрын

    Hi, im almost done with ur tutorial on level system and its great so ty for that. However, i was just wondering how to get items to glow like the door and key. ive got bloom setup but cant get it to work on object except the ones that have a specifik shader.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    You need the Color field to have HDR and increase the intensity kzread.info/dash/bejne/eKqFqMqkg5yWnqw.html

  • @9txmavick31
    @9txmavick312 жыл бұрын

    please make separate video for Pressure Plate Door

  • @stepaburianek8994
    @stepaburianek89943 жыл бұрын

    Your channel has big potencial! Thank you, mb it would be nice to do some time marks so you can skip the video to the part you need xd

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Yup I have started to add timestamps to my recent videos, thanks!

  • @evanraab2104
    @evanraab21043 жыл бұрын

    Awesome tutorial! Maybe you can't do this, but how would you get the position of one of the door you're interacting with using the OverlapCircleAll? Trying to detect which door is closest to the player if there are multiple doors in the overlap circle...

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    OverlapCircleAll gives you all the objects, you can then easily cycle through them and do a distance check

  • @evanraab2104

    @evanraab2104

    3 жыл бұрын

    @@CodeMonkeyUnity lol the answer was in front of me the entire time. Thank you!

  • @terrenceeng9676
    @terrenceeng96762 жыл бұрын

    Hey! this video is very old but i'm wondering if theres anyway to make the button still have a collider like as if it isn't a trigger because i'm making a 2d game unlike the 2.5 in the video and i can't have it passing through the button.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    You can add box a Trigger and a Non-Trigger collider on the same object, just make sure the Trigger is bigger. Alternatively just use a solid non-trigger collider and handle the button interaction by doing Physics.OverlapBox or the 2D version

  • @jaronbaumann9158
    @jaronbaumann91582 жыл бұрын

    Hello! I know this video is quite old but I will still try to get an answer: so I wanted to do the automated door but i get the error "The type or namespace name 'CharacterController2D' could not be found (are you missing a using directive or an assembly reference?)The type or namespace name 'CharacterController2D' could not be found (are you missing a using directive or an assembly reference?)". What do I have to do? (I am new to unity)

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    That's what I named my specific character controller unitycodemonkey.com/video.php?v=Bf_5qIt9Gr8 Although you can use whatever controller you want, nothing too special about my own

  • @tildasart1921
    @tildasart19212 жыл бұрын

    Hey! I'm trying to do the pressure plate thingy but in the DoorInteractPressurePlate for the line "if (collider.GetComponent() != null)" I get an error message saying "'Component.collider' is obsolete: 'Property collider has been deprecated. Use GetComponent() instead. (UnityUpgradable)'" and I'm not entirely sure how to fix it. Do you have any clue?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Did you name the parameter in that function collider? It sounds like you named the parameter something different so by accessing "collider" you are accessing the old deprecated transform.collider of that object instead of the one in the parameter

  • @reneebaghdady2342
    @reneebaghdady23422 жыл бұрын

    Hello, I am creating the automatic door. I am getting one error saying "The type or namespace name 'IDoor' could not be found (are you missing a using directive or an assembly reference?)" It is referencing the IDoor in line 11. I keep looking back and forth to see if I typed anything wrong, but I don't see any difference after I copied yours. Not sure if this makes a difference, but I am doing a 3D game and I changed the everything relating to 2D to 3D already in the code so I'm not sure if IDoor is only for 2D games. If this code only works for 2D, any chance you have any reference videos or a script for automatic doors in a 3D game?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    That's not a built in Unity script, it's an interface I made for the video wth the functions to open/close a door kzread.info/dash/bejne/f46D1KmRm5e-dqw.html

  • @nudecoder991
    @nudecoder9914 жыл бұрын

    ohh i remove the door just like you do... but when i try toggle it back there is no door around my charactor, since i removed it? Not sure how you got around this? :o

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    How are you removing it? Are you calling Destroy() ? If so then the object is destroyed instead of just disabled. Use gameObject.SetActive(false); instead

  • @nudecoder991

    @nudecoder991

    4 жыл бұрын

    @@CodeMonkeyUnity I actually use that setActivity(false) :) But I found another way around it by placing triggers that setActive(false/true)

  • @NeZ3RMWA
    @NeZ3RMWA3 жыл бұрын

    hello i have a problem when i press E"my opendoor button" works fine it opens and close the door the way i set it but i have an error of NullReferenceException Object reference not set to an instance of an object DoorTrigerButton.Update() This is my code :/ [SerializeField] private DoorSetActive door; private void Update() { if (Input.GetKeyDown(KeyCode.E)) { door.OpenDoor(); } }

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    You need to identify what is null kzread.info/dash/bejne/Z52m2JVpXcW6eto.html

  • @trueblue97
    @trueblue972 жыл бұрын

    This is really cool, but how might I accomplish this with the new input system?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    I covered the new input system in detail here unitycodemonkey.com/video.php?v=Yjee_e4fICc These are just basic button inputs, all the collision and interaction logic is the same

  • @trueblue97

    @trueblue97

    2 жыл бұрын

    @@CodeMonkeyUnity Ah ok cool, Ill have to check it out. I feel like the new Input system is a little convoluted tbh, but probably worth switching to just the same

  • @antoll3091
    @antoll30914 жыл бұрын

    Got an error saying Cannot resolve this symbol IDoor, don''t know how to resolve this, can you help me please ?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Sounds like you dont have an IDoor interface defined in your project

  • @PradeepKumar-kk4zd
    @PradeepKumar-kk4zd4 жыл бұрын

    Very nice video bro 🥳🥳🥳

  • @maxim_ssc
    @maxim_ssc2 жыл бұрын

    14:28 Assets\DoorAuto.cs(11,35): error CS0246: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    You don't have any class named "Player" in your project

  • @maxim_ssc

    @maxim_ssc

    2 жыл бұрын

    @@CodeMonkeyUnity oh, ok thanks

  • @dontCallMe..
    @dontCallMe.. Жыл бұрын

    How can i make multiple of these with one animation???

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Not sure what you mean, each door has its own animator component

  • @wasdolgaming6718
    @wasdolgaming6718 Жыл бұрын

    Hi... i know that this video is from 2020 but i need help the animated door gives me this error: 'AnimateDoor' AnimationEvent has no function name specified!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Sounds like you added an animation event to one of the animations but didn't write any function name. Look at the animations in the Animation window and check which one has a little tab icon on the top of the timeline

  • @wasdolgaming6718

    @wasdolgaming6718

    Жыл бұрын

    thanks a lot but it just don't work... Where should i add the scripts?

  • @wasdolgaming6718

    @wasdolgaming6718

    Жыл бұрын

    it does not gives me the error now

  • @magictimm4090
    @magictimm40904 жыл бұрын

    Great video. But please don't skip so fast from script to another. Give it 2 sec :-)

  • @tate_talk574
    @tate_talk5744 жыл бұрын

    Code monkey what program do u use to type in the code for the games plsss tell

  • @NosAltarion

    @NosAltarion

    4 жыл бұрын

    That's visual studio

  • @tate_talk574

    @tate_talk574

    4 жыл бұрын

    @@NosAltarion ty just looked deffernt

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    I use Visual Studio Community 2017

  • @itz_yarno2835
    @itz_yarno28353 жыл бұрын

    Can you make this video but for 2D please

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    This is in 2D. But the logic doesn't care if your game is 2D or 3D, it doesn't matter how the camera is set up.

  • @victorjustino477
    @victorjustino4774 жыл бұрын

    Can you do those things in 3d its so annoying to try to replicate 2d to 3d stuff

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Pretty much every system I make works both in 2D and 3D kzread.info/dash/bejne/Za6stsugmq3YYpc.html

  • @scottgamedev8542
    @scottgamedev85423 жыл бұрын

    im not gonna lie and it sounds mean but your website wont do anything it says i have to sign in to download files then it says i have to validate it when theres no email to validate it

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Check your spam folder

  • @scottgamedev8542

    @scottgamedev8542

    3 жыл бұрын

    @@CodeMonkeyUnity Got it thank you so much

  • @scottgamedev8542

    @scottgamedev8542

    3 жыл бұрын

    @@CodeMonkeyUnity Poor boy that's a lot of scripts

  • @coryburnsgamedev
    @coryburnsgamedev4 жыл бұрын

    Will this work for a 3D project?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Sure, the code is mostly the same regardless of the assets, just change 2D colliders for the 3D ones

  • @coryburnsgamedev

    @coryburnsgamedev

    4 жыл бұрын

    @@CodeMonkeyUnity Thanks! Love the vids

  • @Targetnetnews
    @Targetnetnews2 жыл бұрын

    So this is top down game. Is this also work with 2D game

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Not sure what you mean, this is all in 2D

  • @phuctrangia3593
    @phuctrangia35934 жыл бұрын

    Video about using raycast to interact door with key in 3d plz. I think its will be great !

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    What do you mean raycast? Open the door when you have the key and press a button? Combine the key method with the button method

  • @phuctrangia3593

    @phuctrangia3593

    4 жыл бұрын

    @@CodeMonkeyUnity yeah. I have tried to combine your code but its not worked. Can you make a video about this

  • @dariasfortis8850
    @dariasfortis88502 жыл бұрын

    I'm pretty much at my wits end. I'm new to this coding stuff I tried to do only the auto door funcions, but every time it writes some damn error about instance enchanting table something. I tried to use it somehow fron these 3 scripts but errors just keep going. Does anyone see anything in it? It's just so complicated I went trough all 3 videos on these doors and I am totally lost. //interface script public interface IntfDoor { void OpenDoor(); void CloseDoor(); } //animation door script public class DoorAnimate : MonoBehaviour, IntfDoor { private Animator animator; private void Awake() { animator=GetComponent(); } public void OpenDoor() { animator.SetBool("Open", true); } public void CloseDoor() { animator.SetBool("Open", false); } } //Autodoor function script public class DoorInteractAuto : MonoBehaviour { [SerializeField] private GameObject doorGameObject; private IntfDoor door; private void Awake() { door = doorGameObject.GetComponent(); } private void OnTriggerEnter(Collider collider) { if (collider.GetComponent() !=null) { door.OpenDoor(); } } private void OnTriggerExit(Collider collider) { if (collider.GetComponent() !=null) { door.CloseDoor(); } } }

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    What is the actual error? Looking at what the error says will tell you what is wrong and what line the error happened. Could be you did not assign the doorGameObject reference Could be the door does not have an Animator Could be the door does not have a DoorAnimate script

  • @dariasfortis8850

    @dariasfortis8850

    2 жыл бұрын

    @@CodeMonkeyUnity 1st NullReferenceException: Object reference not set to an instance of an object DoorInteractAuto.OnTriggerEnter (UnityEngine.Collider collider) (at Assets/Door/DoorInteractAuto.cs:21) 2nd NullReferenceException: Object reference not set to an instance of an object DoorInteractAuto.OnTriggerExit (UnityEngine.Collider collider) (at Assets/Door/DoorInteractAuto.cs:29) I checked it's on lines with door.OpenDoor() and door.CloseDoor()

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    ​@@dariasfortis8850 Then you have the door reference set to null, add a Debug.Log to verify kzread.info/dash/bejne/Z52m2JVpXcW6eto.html Then look at how you're grabbing that reference, either a missing component or missing editor reference.

  • @dariasfortis8850

    @dariasfortis8850

    2 жыл бұрын

    @@CodeMonkeyUnity THANK YEE MATEY I found the problem I tried to place all the stuff on doorway object and have it only move the door but in your video ya had a separate object for the handeling the trigger area. So now it work thanks to you again matey :D

  • @liamanimation7837
    @liamanimation78373 жыл бұрын

    2d game?

  • @tranceemerson8325
    @tranceemerson83253 жыл бұрын

    isn't it bad enough we have to wear those damned masks in public, then you go on making your game character wear one too? I would like a chance to sit and relax and not be thinking about COVID. Aside from that great work.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    What? That's a beard

  • @trueblue97

    @trueblue97

    2 жыл бұрын

    @@CodeMonkeyUnity Yo guys, it somehow looks like both. Just what sort of optical illusion have you created here!? lol