Simple Key Door System in Unity

✅ Get the Project files and Utilities at unitycodemonkey.com/video.php...
Let's make an Awesome Key Door System! Grab Keys and Open the correct Doors!
I made an FPS in 5 days! (Unity Microgame)
• I made an FPS in 5 day...
Sprite Outline (Animated!) - 2D Shader Graph Tutorial
• Sprite Outline (Animat...
Simple Inventory System in Unity (Store, Use, Stack and Drop Items)
• Simple Inventory Syste...
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!
🤖 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

Пікірлер: 202

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

    Here's another excellent System used in the FPS Microgame! Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel! Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php

  • @christianmccauley7340

    @christianmccauley7340

    4 жыл бұрын

    How did you make this work in 3D? Im working on a VR game right now and im having trouble making the collision between the character and the key work.

  • @HyperSource

    @HyperSource

    6 ай бұрын

    @@christianmccauley7340 it should show in the included readme.

  • @nchutchind
    @nchutchind4 жыл бұрын

    I think you have the best variety of tutorial videos for beginner/intermediate Unity game development. Your videos are very well produced and convey their information very clearly. I wish I could like your videos more than once.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Thanks!

  • @dylancurry5499

    @dylancurry5499

    3 жыл бұрын

    @@CodeMonkeyUnity Hey, can you help me? Ive copied the code but i have errors please help: { private List keyList; private void Awake() { keyList = new List(); } public void AddKey(Key.KeyType keyType) { keyList.Add(keyType); } public void RemoveKey(Key.KeyType keyType) { keyList.Remove(keyType); } public bool ContainsKey(Key.KeyType keyType) { return keyList.Contains(keyType); } private void OnTriggerEnter2D(Collider2D collision) { Key key = collider.GetComponent(); //Error on this row if (key != null) { AddKey(key.GetKeyType()); Destroy(key.gameObject); } } } I get the error property collider has been deprecated. Any help would be good, Thanks!

  • @viktorvanchov3093
    @viktorvanchov30934 жыл бұрын

    You're one of the most useful unity turtorial channels, thank you so much for making these turtorials and please don't stop making them.

  • @maxdart
    @maxdart4 жыл бұрын

    Also thanks for the game bundle! Just picked it up and will surely check out all your titles.

  • @eruaiokoyomoh3177
    @eruaiokoyomoh31774 жыл бұрын

    I've been waiting for a video like this

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

    Check out the complete FPS Microgame Playlist for more Tutorials kzread.info/head/PLzDRvYVwl53sQhBZF00eC3SW09HJivZMH

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

    For those having problems with the base key template image being shown instead of the correct colored one once you pick up the first key... change keyTemplate.gameObject.SetActive(true); to keyTransform.gameObject.SetActive(true); in the UpdateVisuals Function that fixed the issue for me!

  • @gary909

    @gary909

    11 ай бұрын

    Thank you! 👍👍

  • @gamedevel22
    @gamedevel224 жыл бұрын

    Nice and clean coding! So easy to follow along

  • @wolfonprowell1946
    @wolfonprowell19463 жыл бұрын

    This is so helpful! The way you explained help me understand how to read and apply the code better. Thank you so much! :D

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Awesome! I'm glad to hear it!

  • @suicune2001
    @suicune20012 жыл бұрын

    Awesome! This is exactly what I needed.

  • @RoronoaShu27
    @RoronoaShu274 жыл бұрын

    Awesome tutorial!

  • @QuappsInteractive
    @QuappsInteractive4 жыл бұрын

    Perfect, thank you 👍

  • @Sputterbugz
    @Sputterbugz3 жыл бұрын

    quick and simple, nice work

  • @daibergonzalez6498
    @daibergonzalez64984 жыл бұрын

    You make awesome Unity tutorials

  • @Smil3rFPS
    @Smil3rFPS4 жыл бұрын

    This helped a lot with my burglar escape game! Thank you

  • @mmo_7969
    @mmo_79693 жыл бұрын

    This video was extremely helpful, thank you so much!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    I'm glad to hear it! Thanks!

  • @Sputterbugz
    @Sputterbugz3 жыл бұрын

    tysm yours is the only tutorial thats worked for me and im crunching for a school project T_T

  • @maxdart
    @maxdart4 жыл бұрын

    awesome video as usual! Could you cover the best (most efficient) ways of binding entities to UI? Like in case of health bar following your zombie around in ECS based game.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    I'm currently waiting for 2019.3 to come out so I can get back to making tons of DOTS videos. UI is definitely something I want to look into.

  • @wiggz89
    @wiggz893 жыл бұрын

    Hey Code Monkey, thanks for the great tutorial! Is it possible to make a door require multiple key types? For example, I would like a door which requires both a blue and a green key in order to open it.

  • @hoangminhnguyen2191
    @hoangminhnguyen21914 жыл бұрын

    Question: how to set up post processing after import the asset, i always got null for ambientocclusion

  • @danbryandalisay8547
    @danbryandalisay85474 жыл бұрын

    thank you so much and you really help this so alot, but i have a problem, when i start the UI_KeyHolder is not active, but when i get the key, the UI_KeyHolder is still not active,,,. I follow all your steps but still i cant find it, sorry for my bad grammar😅

  • @Mnap
    @Mnap3 жыл бұрын

    How to make it so the key only works if it has a parent (for example: hand) and the key is active?

  • @sirstrik7402
    @sirstrik74024 жыл бұрын

    What took you so long to make this kind of tutorial?!! Great stuff tho, as usual.

  • @tuomaslaitinen9360
    @tuomaslaitinen93604 жыл бұрын

    you make awesome videos and you have helped me alot:) but can you do videos about 2d platformers that would help me alot.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    I've done a few and would definitely like to do more kzread.info/head/PLzDRvYVwl53sPOJQt-7Nb-a0n_XEcQotB

  • @SlinderPigGaming22
    @SlinderPigGaming224 жыл бұрын

    In fps micro game it says keydoorsystem_player.cs is giving a warning saying it's not assigned how to fix this

  • @VoidShadow66
    @VoidShadow669 ай бұрын

    How to get the Text numbers of keys which has a Player , on the screen on canvas?? Tell us please , i don't understand where and what to write in code.

  • @gyatobro
    @gyatobro6 ай бұрын

    can you make a video where you dont go trought the but when you open it with the key you click e and teleport yourself to the other door pls i need help

  • @godspeedguy
    @godspeedguy2 жыл бұрын

    I followed the README instructions in the fps microgame and it just gives me an error when I try to put the DoorKeyHolder script into the player. "Can't add script component "DoorKeyHolder" because the script class cannot be found. Please make sure that there are no compile errors and that the file and class name match." Please help!

  • @ItsShazOne
    @ItsShazOne4 жыл бұрын

    so how to make when we take the key, enter the door and get the star.... a sound playing?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Check out this video on a Simple Sound Manager: kzread.info/dash/bejne/g4Bmm8ONkZqwZbQ.html

  • @darrylvillanueva5233
    @darrylvillanueva52333 жыл бұрын

    how to do the animation for opening the door?

  • @brotherbearvalter
    @brotherbearvalter2 жыл бұрын

    Okei this code doesnt work for me. After installing the UI_Keyholder code when i pick up the key, the sprite doesnt get deleted. And when i pick up the key, canvas shows a new KeyTemplate clone but both KeyTemplates are invisible. I have no idea how to fix this

  • @forestgump2081
    @forestgump20813 жыл бұрын

    Hello, I'm writing late, of course, but you never know. I have such a mistake that the door collapses even if you enter the trigger without a key, could there be a problem?

  • @Ayce71
    @Ayce712 жыл бұрын

    If you have 2 red keys, is there a way to make it so that opening a red door only consumes one of the red keys and not all of them? Thank you, anyone

  • @jrose111284
    @jrose1112842 жыл бұрын

    Hi, is it possable to use dont destroy on load with this? As when i leave a scene the doors and keys rest? if so what files would i use it on? many thanks great video

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Technically it's possible but that would be very messy, you'd keep the door in the same position over multiple scenes. Much better to just store the state whether its opened or closed and set the door to that state when loading the scene

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

    Love these videos and was excited to try this system! But I immediately ran into a code error of "GameConstants not found" and I can't even test the game I've built so far until I fix it now...I commented out that section of code for now, but what coding am I missing or what adjustments should I make to get the full code to work?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Yeah you can just comment that. The asset was made specifically to work with the Unity FPS Microgame which is where those constnats are defined but it works on any project

  • @ashmeetsingh2116
    @ashmeetsingh21163 жыл бұрын

    Thanks for such an awesome assist. I have 1 question thought , Can you please tell me how do I close the door after it has been opened once.... I am aiming to open the door for the first time when the player has the key but the door should close after the player moves away from it and it should open again when the player comes back to the 2cd time

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    You can add some sort of state machine logic on the door, keep track if its already been unlocked and if so add a simple timer to close and reopen when the player gets close

  • @ashmeetsingh2116

    @ashmeetsingh2116

    3 жыл бұрын

    @@CodeMonkeyUnity Actually I am new to unity and have no experience with C#. So I do not know how to add the things you have suggested. I also tried to uderstad the code which came with the asset and also tried to edit work things out as I wanted but unfortunately it did not happed

  • @jrose111284
    @jrose1112843 жыл бұрын

    Hi great video, So i donwloaded your package to test it with the animation. But each animation field is using transfrom.postion, So when i add the door and move it and press play the door appears were you set the animation. Is there away to fix this or do i have to edit each animation state, like idle etc.... And if i have to edit each animation how do you add more then one dppr as it will still get its position from the last animation. Thanks

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    This video was made a long time ago so I really don't remember the specifics. If I did make the animation modify the root then yeah that can cause issues. What I normally do is keep the sprites as a child and move those in their local positions, that way the animation works anywhere. But if I did make them moving the root then yeah the only way is to remake the animations to move the children instead.

  • @adamantium6400
    @adamantium64003 жыл бұрын

    Hi, fantastic tutorial. Thanks. Question: I set the key list to public so I can see when I have a key, when I open the door it destroys the key which is great, however if I go to the door before I go and get the key it still opens. Not sure how to solve this. Any help would be appreciated.

  • @adamantium6400

    @adamantium6400

    3 жыл бұрын

    Solved it, I'm an idiot. For anyone else with the issue, at the location on the Key Holder were you write if (ContainsKey(keyDoor.GetKeyType())) I had a ; at the end. This screwed it all up.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Yeah that's tricky, always be very careful with misplaced ;

  • @infernogamey374
    @infernogamey3742 жыл бұрын

    this is also possebel for 3d games right not only 2d?

  • @dylancurry5499
    @dylancurry54993 жыл бұрын

    Hey, can some one help me? Ive copied the code but i have errors please help: { private List keyList; private void Awake() { keyList = new List(); } public void AddKey(Key.KeyType keyType) { keyList.Add(keyType); } public void RemoveKey(Key.KeyType keyType) { keyList.Remove(keyType); } public bool ContainsKey(Key.KeyType keyType) { return keyList.Contains(keyType); } private void OnTriggerEnter2D(Collider2D collision) { Key key = collider.GetComponent(); //Error on this row if (key != null) { AddKey(key.GetKeyType()); Destroy(key.gameObject); } } } I get the error property collider has been deprecated. Any help would be good, Thanks!

  • @mechanicaldragons4896

    @mechanicaldragons4896

    Жыл бұрын

    I'm having the same issue null error

  • @emichaosurban
    @emichaosurban2 жыл бұрын

    A curious question, if i want it to have a inventory limit, should I use array instead of list?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    You can use either of them, just check either array.Length or list.Count

  • @aryelsander7296
    @aryelsander72964 жыл бұрын

    I can't find in your channel this sprite outline 2D Shader Graph video.

  • @Sampza12

    @Sampza12

    4 жыл бұрын

    Me neather

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Yeah I've made the effect but haven't finished the video yet, should hopefully be out on Sunday.

  • @aryelsander7296

    @aryelsander7296

    4 жыл бұрын

    @@CodeMonkeyUnity i will use in my game, can't wait!

  • @457Deniz457

    @457Deniz457

    4 жыл бұрын

    @@CodeMonkeyUnity Thanks :)

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Here's the Sprite Outline effect: kzread.info/dash/bejne/eKqFqMqkg5yWnqw.html

  • @josephmorgan963
    @josephmorgan9634 жыл бұрын

    I keep getting a cannot implicitly convert type 'void' to 'bool', how can I fix it? It is between lines (42,17),I don't know how to fix it

  • @hikarirock

    @hikarirock

    3 жыл бұрын

    if you already fix it, That would happen when you put void bool instead of public bool. The reason could be the code is trying to get access to that statement.

  • @ubcbrasil
    @ubcbrasil4 жыл бұрын

    Perfeito seus tutoriais, conheci a pouco tempo e estou gostando bastante. O meu aconteceu um bug, quando pego uma chave, aparecem duas em minha carteira. O que pode ser?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Será que tens duas chaves uma em cima da outra? Adiciona varios Debug.Log(); para ver exactamente o que o codigo esta a fazer. Podes tar a chamar a funcao para adicionar o item 2 vezes.

  • @ubcbrasil

    @ubcbrasil

    4 жыл бұрын

    @@CodeMonkeyUnity Descobri, modifiquei o nome do script para key2(para fazer um teste) pois já tinha um script com o nome (key) e de alguma forma as chaves estavam duplicando rsrsrs, removi e deixei como (key) e de certo. Não sei porque, mas apenas os nomes eram quase iguais, os scripts eram diferentes. Você é excelente, parabéns pelos tutoriais, um dos melhores.

  • @creatoruni9673
    @creatoruni96733 жыл бұрын

    Hi, great tutorial btw but i seem to have a problem that when i pick up the key it works, but when i go to the door, it doesnt open? im not sure what im doing wrong

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Is your collision triggering? kzread.info/dash/bejne/dJdtzs-BmtSyisY.html

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

    would this typr of coding work on something like the fps microgame in unity?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Sure, there's nothing here that is specific to any game genre

  • @micaiahstevens8840
    @micaiahstevens88404 жыл бұрын

    Curious programming question: You seem to prefer to use a GetDoorType() method instead of a DoorType { get; } [Example - to most code standards] I Get a Method can do a lot more. I often do a larger get { if DoorType == Red ; do something else} Anyways just curious on your thoughts of the two types of ways to get Variables.

  • @micaiahstevens8840

    @micaiahstevens8840

    4 жыл бұрын

    P.S. If you DO a Are you SURE you want to open this door, let me open the other one mini game I am going to CRY!

  • @micaiahstevens8840

    @micaiahstevens8840

    4 жыл бұрын

    COULD just be your preference, if I am returning a list of values, I convert it to an array to sorta be like THIS isn't meant to be changed.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    It's just preference, a property get; and a GetDoorType(); function do exactly the same. I like to be as explicit as possible in my code so that's why I prefer to make Get functions rather than using the property which looks like a variable but really works as a function.

  • @tigransahakyan2840
    @tigransahakyan28404 жыл бұрын

    Great! But how did you made doors animation?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Using Unity's Animator, its very simple just Open and Close.

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

    I used this for 3d game and it worked perfectly but how can i press e then open the door and press e again to close the door ?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    I've just posted a video on multiple ways of interacting with doors kzread.info/dash/bejne/dH5oxLB_gNiqh6Q.html Combine the Key with the Button method.

  • @phuctrangia3593

    @phuctrangia3593

    4 жыл бұрын

    @@CodeMonkeyUnity can you make a video about using raycast to interact about door and key in 3d game pls ? Its would be awsome

  • @krizttyxd
    @krizttyxd2 жыл бұрын

    This is the great video that i want! /// What i can do if i want to press f to pickup a key and press f again to open the door??

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Maybe use an Interface to interact with objects kzread.info/dash/bejne/dH5oxLB_gNiqh6Q.html kzread.info/dash/bejne/f46D1KmRm5e-dqw.html

  • @pinhoug
    @pinhoug4 жыл бұрын

    I have the Error : Assets/Key.cs(7,17): error CS0102: The type `Key' already contains a definition for `keytype' can you Help me ?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Sounds like you defined two types with the exact same name.

  • @pinhoug

    @pinhoug

    4 жыл бұрын

    @@CodeMonkeyUnity I dont think so, but i find no mistake

  • @bdn_st

    @bdn_st

    4 жыл бұрын

    I found it, in the part of the [SerializeField] private KeyType keyType;

  • @barto2439
    @barto24393 жыл бұрын

    So for some reason, after I pick up the first key, in the UI it shows the base key template instead of the right colour. After I pick up the second key it looks as if everything was fine but I can see in the hierarchy that the template is just behind one of the keys and becomes visible again after I use all the keys. My code looks exactly like on the video and now I became kind of desperate

  • @jagdishsahu3935

    @jagdishsahu3935

    2 жыл бұрын

    same problem!

  • @alcreative5931

    @alcreative5931

    Жыл бұрын

    @@jagdishsahu3935 same here... :( after using all keys, I still see the UI image which makes it look as if i still have one more key left. Did anyone managed to solve this ?

  • @alcreative5931

    @alcreative5931

    Жыл бұрын

    solved it: change keyTemplate.gameObject.SetActive(true); to - > keyTransform.gameObject.SetActive(true);

  • @madhavanarra2152
    @madhavanarra21524 жыл бұрын

    can you make a video of this in the unity FPS microgame so I dont need to try and switch between 2d and 3d

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    The Key Door System Asset contains a detailed ReadMe and Demo Scene with instructions on how to add it assetstore.unity.com/packages/templates/systems/key-door-system-fps-microgame-approved-add-ons-175210

  • @madhavanarra2152

    @madhavanarra2152

    4 жыл бұрын

    @@CodeMonkeyUnity thanks you are the best

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

    how to add animation to door

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Just like you add an animation to anything. Add an Animator, create an animation

  • @djvv4049
    @djvv40494 жыл бұрын

    OK so I'm getting the key image to appear on the UI not altered when i first pick up a key then when a grab a second key they both show up correctly, then when i open the doors the first key get consumed/remover correctly. however after opening the second door the original image appears again. Not sure what I'm doing wrong, public class UI_KeyHolder : MonoBehaviour // "UE}..." [SerializeField] private KeyHolder keyHolder; private Transform container; private Transform keyTemplate; private void Awake() { container = transform.Find("container"); keyTemplate = container.Find("keyTemplate"); keyTemplate.gameObject.SetActive(false); } private void Start() { keyHolder.OnKeysChanged += KeyHolder_OnKeysChanged; } private void KeyHolder_OnKeysChanged(object sender, System.EventArgs e) { UpdateVisual(); } private void UpdateVisual() { // Clean up old Keys foreach (Transform child in container) { if (child == keyTemplate) continue; Destroy(child.gameObject); } // Instantiate Current Key List List keyList = keyHolder.GetKeyList(); for (int i = 0; i { Key.KeyType keyType = keyList[i]; Transform keyTransform = Instantiate(keyTemplate, container); keyTemplate.gameObject.SetActive(true); keyTransform.GetComponent().anchoredPosition = new Vector2(50 * i, 0); Image keyImage = keyTransform.Find("image").GetComponent(); switch (keyType) { default: case Key.KeyType.Red: keyImage.color = Color.red; break; case Key.KeyType.Green: keyImage.color = Color.green; break; case Key.KeyType.Blue: keyImage.color = Color.red; break; }.....zzz

  • @Rick-Arg

    @Rick-Arg

    3 жыл бұрын

    same problem, how did you fixed it?

  • @aaroon1993

    @aaroon1993

    2 жыл бұрын

    same here, did you solved it?

  • @ultramarioyt101
    @ultramarioyt1013 жыл бұрын

    Is there a way to use this in a 3D game.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Of course, the underlying system doesn't care if the door is a sprite or a 3D mesh kzread.info/dash/bejne/Za6stsugmq3YYpc.html

  • @mizar430
    @mizar4303 жыл бұрын

    How do i make the door require multiple keys to open? For example: Door 1 requires (Green and Red Key)

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Just modify the code so that the door has a field for the list of keys instead of just one key. Then when you open cycle through the list and see if the player has all the keys in the door key list.

  • @dontassumably3603

    @dontassumably3603

    3 жыл бұрын

    @@CodeMonkeyUnity Does that mean making an array or smth else?

  • @HyperSource
    @HyperSource6 ай бұрын

    @CodeMonkeyUnity help, i imported the assets without the "project settings" to not override the things and make the entire level pink, but the doors and keys still render as pink. they work, the FPS microgame works, and the doors are the only thing. pls help!!!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    6 ай бұрын

    Pink means shader error, I don't remember what shader I used in the included files, either you're using the Built In Render Pipeline or URP and you need to match that on the shader

  • @HyperSource

    @HyperSource

    6 ай бұрын

    @@CodeMonkeyUnity alright, how do i change it? and how do i find which one i'm using? sorry im a noob at unity

  • @DWIWindsands
    @DWIWindsands2 жыл бұрын

    Hey can you help me get this please? My issues are when I collide with the door & I have the key nothing happens. When I try to make it the way I'd like it that the door destroys itself (no animations) when my player collides it would be great. But when I try the door disappears when I collide rather I have key or not. I can't seem to get the UI thing working either. I did your tutorial but when I try to incorporate it into my game nothing works.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Add some Debug.Log to see what your code is doing, and make sure all collisions are working correctly kzread.info/dash/bejne/dJdtzs-BmtSyisY.html

  • @DWIWindsands

    @DWIWindsands

    2 жыл бұрын

    @@CodeMonkeyUnity According to my Debug.Log everything works as your video says it does. My doors (which are animated) don't stop opening & closing.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    @@DWIWindsands Then maybe its not the code but rather the animator that is set up incorrectly, check the transitions, maybe you have one with exit time enabled which will make it transition when the naimation ends instead of when the trigger parameter is called

  • @DWIWindsands

    @DWIWindsands

    2 жыл бұрын

    @@CodeMonkeyUnity Do you have a video on that? I was gonna hit you in the discord I joined yesterday. I really appreciate your help& am sure it's something simple I'm not getting.

  • @DWIWindsands

    @DWIWindsands

    2 жыл бұрын

    @@CodeMonkeyUnity I got it dude you're the man. Thank you.

  • @laszlomezei9046
    @laszlomezei904610 ай бұрын

    Hello. It's a very good tutorial but I have a problem. When I pick up the key and reach the trigger zone the door animation doesn't working. It's just disappearing. :/ The animation is on the sprite and If I try when the game is not playing it's good, but when I'm playing it's just disappear. Do you have any guess why is it happening ?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    10 ай бұрын

    Pause the game and inspect how exactly is it disappearing. Maybe it's moving on the Z behind the camera? Maybe the scale is going down to 0? Maybe the game object is being destroyed?

  • @laszlomezei9046

    @laszlomezei9046

    10 ай бұрын

    It is dissapearing exactly when you show in the video before you put the animation on your doors. It's just pop out. You pick up the key, go to the trigger zone and the door dissapearing and I can go through it. So that's how it should work. I was thinking and what I'm seeing is that you have an " animedoor script " on your doors and that's missing for me. Is there any video where you show how you make that script ? Because I think that's the reason why my animation doesn't appear when I play on my doors, doesn't it ? 🤔 ( I'm an absolutely newbie so thank you for the answer 😁 ) @@CodeMonkeyUnity

  • @user-yh8hh9cy3k
    @user-yh8hh9cy3k4 жыл бұрын

    how did you do the door animation? can you show a mini guide?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Its done with the Unity Animator, it's pretty simple just a Open and Close Animation, you can get the project files to look at it.

  • @user-yh8hh9cy3k

    @user-yh8hh9cy3k

    4 жыл бұрын

    thanks!)

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

    I have a slight problem with mines, I have copied and even verified the code, all game objects and components in those game ojects involved in my game. The problem is that once i used up the key by opening a door, the key icon for that key does not disappear from the UI. How can I fix this?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Is it just the UI? Does the player no longer hold that key? Maybe you just forgot to update the UI when updating the player key list

  • @komradwide4660

    @komradwide4660

    Жыл бұрын

    ​@@CodeMonkeyUnity ok so I was experimenting around some more. In the video you set the source sprite of the image object (inside keyTemplate) to a key color green right? For mines I did not change the color so its just plain white. What I found out is that if my player only has 1 key in his inventory, it will display only the color of the image object which is, again, plain white. But if I have 2 or more keys then it will display all keys side-by-side in their correct colors but if it even goes back to just 1 key, the color of the key is plain white. If i DID consume the last key, the icon does not go away. So I guess the problem lies with the UI because I tested out 3 different keys and there was no problem with them at all. What part of the code should i fix/edit?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    Add some Debug.Log to see what your code is doing, see how often you are updating the visual, see if the events are being fired correctly

  • @SonLCV
    @SonLCV4 жыл бұрын

    How can i use "using.CodeMonkey" in my script? please help

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Download the Utilities and double click the UnityPackage to add it to your Project.

  • @ASMRcu
    @ASMRcu4 жыл бұрын

    Awesome......sir plz make a Auto Aim or Aim asist tut ....in whole youtube no one make Aim asist video sir please be the first ......

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    That's an interesting topic, I'll look into it.

  • @ASMRcu

    @ASMRcu

    4 жыл бұрын

    @@CodeMonkeyUnity sir i make it but it wasn't efficient approach for low end devices....while casting tons of rays creating Sphereoverlaps/frame consume alot of memory ....

  • @jordanbrett8215
    @jordanbrett82154 жыл бұрын

    Does this work for 3D games?

  • @VojaGames

    @VojaGames

    3 жыл бұрын

    I dunno

  • @JuliaMagote
    @JuliaMagote2 жыл бұрын

    Does this work with 3D aswell?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Yes, the system doesn't care if your door is a Sprite or a Mesh

  • @jldo1342
    @jldo13422 жыл бұрын

    I cant open the package in unity all color pink... can you guys help me..

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Run the URP material upgrader

  • @jldo1342

    @jldo1342

    2 жыл бұрын

    @@CodeMonkeyUnity Thank you so much for replying but im new to this can i ask where is the URP material upgrader?

  • @Michal005
    @Michal0054 жыл бұрын

    when will you do crafting system

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    It's on my list

  • @Rick-Arg
    @Rick-Arg3 жыл бұрын

    Hello, Code Monkey! Can I ask you about code please? When I pick up key, my base template is turning on, but key which I picked up is hidden. After I pick up second key, all work good. But base template is not hidden. How should I fix this? Sorry for bad english...

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Make sure you're not mixing the keyTemplate and keyTransform. The template should only be used for cloning.

  • @Rick-Arg

    @Rick-Arg

    3 жыл бұрын

    @@CodeMonkeyUnity yeah, i understood it yersterday and fixed it. Thanks for your answer!

  • @lolsplaying6629

    @lolsplaying6629

    3 жыл бұрын

    How did you fixed it ? I still can't understand [Edit] i just change in line 39 from "keyTemplate" to "keyTransform" and it fixed.

  • @carlosespinoza7994

    @carlosespinoza7994

    2 жыл бұрын

    @@lolsplaying6629 Thanks friend

  • @dipsherlock

    @dipsherlock

    2 жыл бұрын

    @@lolsplaying6629 oh my god you're literally a life saver thank you so much

  • @xDDean
    @xDDean4 ай бұрын

    Hippity hoppity your code is now my property

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 ай бұрын

    I hope it helps! Best of luck with your game!

  • @thescarblaze1061
    @thescarblaze10614 жыл бұрын

    My key in the UI did not disappear even after I used my key. Where did I do wrong?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Does the KeyHolder in the player still have the key? You can make the keys consumable or not If the key was indeed destroyed add some Debug.Log(); to figure out if the UI is listening to the events

  • @thescarblaze1061

    @thescarblaze1061

    4 жыл бұрын

    @@CodeMonkeyUnity I wrote the Debug.Log("Removed key"). I have even placed a second door for insurance. I open the first door, the second doesn't open and the key still exists on the screen.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    @@thescarblaze1061 So was the log triggered or not? Sounds like the key is being destroyed but your UI is not listening to that event.

  • @cykeedits8296
    @cykeedits82963 жыл бұрын

    Can we pick up multiple keys at once??

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Sure, the code uses a List to store them.

  • @cykeedits8296

    @cykeedits8296

    3 жыл бұрын

    @@CodeMonkeyUnity Thanks!! You are great.

  • @pelethehedgehog9444
    @pelethehedgehog94443 жыл бұрын

    Everything works, except that when I pick up the key, the game pauses when I pick up the key in Unity Editor, but not when I have built the game.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    The build ignores errors and continues running while the editor is set to pause on error by default. Check what error youre getting and fix it

  • @pelethehedgehog9444

    @pelethehedgehog9444

    3 жыл бұрын

    @@CodeMonkeyUnity I don't really understand what errors say in general in Unity. The error says "NullReferenceException: "Object reference not set to an instance of an object"

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    @@pelethehedgehog9444 Means youre trying to access an object that is set to null

  • @davidconner1028
    @davidconner10283 жыл бұрын

    In the Key Holder script on line 27 I'm getting an error code that says it is using an Obsolete API. I allowed unity to update it, but it doesn't do what I wanted it to do like in the video. Help would be appreciated.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    What is on line 27?

  • @davidconner1028

    @davidconner1028

    3 жыл бұрын

    @@CodeMonkeyUnity Key key = collider.GetComponent();

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    @@davidconner1028 The collider property is no longer used, do gameObject.GetComponent() To get the key just do gameObject.GetComponent()

  • @davidconner1028

    @davidconner1028

    3 жыл бұрын

    @@CodeMonkeyUnity Ok so I tried using this for line 27 now, but it still doesn't grab the key. I changed the Collider to Collider2D because I'm using a 2D collider. Key key = gameObject.GetComponent().gameObject.GetComponent();

  • @holyrocketbunny2801

    @holyrocketbunny2801

    3 жыл бұрын

    @@davidconner1028 i have the same problem did you find a solution ?

  • @kayaboeties6016
    @kayaboeties60163 жыл бұрын

    Does this work for a 3D game bro?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Yes, just replace the sprites with 3D meshes kzread.info/dash/bejne/Za6stsugmq3YYpc.html

  • @ErickFranz
    @ErickFranz4 жыл бұрын

    After Last!!! xD

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

    where's the 3d one? very good tutorial by the way

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    Жыл бұрын

    The logic is all the same, only difference is using 3D components unitycodemonkey.com/video.php?v=3zxTigjJr24

  • @Joesephicus

    @Joesephicus

    Жыл бұрын

    @@CodeMonkeyUnity Thanks!

  • @fatrickwashere3072
    @fatrickwashere30723 жыл бұрын

    Does this work in 3d?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Yes, the visuals are separate from the logic so you can use Meshes instead of Sprites

  • @fatrickwashere3072

    @fatrickwashere3072

    3 жыл бұрын

    @@CodeMonkeyUnity Thank You!

  • @owo3230
    @owo32303 жыл бұрын

    Does this work for a 2D Platformer too?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    Sure, the logic doesn't care how the sprites are drawn

  • @owo3230

    @owo3230

    3 жыл бұрын

    Okay thanks ^_^

  • @owo3230

    @owo3230

    3 жыл бұрын

    U‘r great and I learned many things from you

  • @goldencookie5456
    @goldencookie54564 жыл бұрын

    This is *important* Game development videos are obviously not directed towards kids, but I have big feeling that the FTC is going to claim that these vids are for children, considering how they said that anything cartoon related or game related will be considered "for kids". If you don't know, the Federal Trade Commission (FTC) has fined KZread $170m, because of how they violated the Children's Online Privacy Protection Act (COPPA). KZread basically collects data on people on KZread, and that isn't allowed on children under the age of 13, unless the permission/consent of the parents are given. So they are now forcing a new rule onto youtube. The rule is that every content creator will have to either tick their videos as "for kids" or "not for kids". If you tick is as "not for kids", but the FTC disagrees upon that, they will and can fine the content creator $42,000 per video. Furthermore, videos that are considered as "for kids" by the FTC will get 90% less revenue, comments won't be allowed, notifications won't be allowed, and the videos won't be found on recommended and on the search bar. This change will happen near January of 2020, but the FTC is giving a chance, and you are able to give feedback. And hopefully, they will change their mind. Search up some videos about this for more details and try to spread this. I don't think all people are aware of this change. This is very very important if you're a content creator.

  • @jirikaminsky6397
    @jirikaminsky63974 жыл бұрын

    Please more tutorials for micro fps , like multiple weapons with animations, Or flying enemies like helicopter from half life 2

  • @windar2390
    @windar23904 жыл бұрын

    Gunpoint mechanics

  • @user-sk3tf6yk9d
    @user-sk3tf6yk9d4 жыл бұрын

    I'm korean! Thank you!

  • @mnrs2562
    @mnrs25622 жыл бұрын

    Could you please tell me what's the point of that much coding? I could do that with 10 lines of codes but if there is a logic behind your codes, i would like to use it.

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    Not sure what you mean by "that much coding", there's nothing in the code that is unnecessary, everything has a purpose. If you just want to open a door without any key system then sure just 1 line to play an animation. Also the most compact way is not usually the best way, you should always focus on writing good clean code kzread.info/dash/bejne/onhmmbuueqqZfJs.html

  • @adam.coding-games
    @adam.coding-games5 ай бұрын

    a bit late to the party but i also need some help - everything works as intended (i think) but when i run my game, the template is already showing which makes it when i pick up new keys, the UI isn't being updated. i did do keytemplate.gameobject.setactive(false) but its still showing the template when the game is run

  • @Ateeqspecial
    @Ateeqspecial4 жыл бұрын

    First

  • @TheLockyMichael
    @TheLockyMichael4 жыл бұрын

    Last

  • @honorlife6679
    @honorlife66794 жыл бұрын

    Second

  • @mojang7237
    @mojang72373 жыл бұрын

    After last

  • @scotttowers1759
    @scotttowers17592 жыл бұрын

    Copied word for word and get a whole host of errors :(

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    What errors? Step one is identify what actually is the problem kzread.info/dash/bejne/Z52m2JVpXcW6eto.html

  • @scotttowers1759

    @scotttowers1759

    2 жыл бұрын

    @@CodeMonkeyUnity thanks for responding, really helps when a tutorial channel stays active in the comments. I'll try again today and reply with the error message that I get :)

  • @scotttowers1759

    @scotttowers1759

    2 жыл бұрын

    @@CodeMonkeyUnity Scripts\KeyHolder.cs(20,39): error CS0426: The type name 'KeyType' does not exist in the type 'KeyHolder' KeyHolder.cs(7,28): error CS0426: The type name 'KeyType' does not exist in the type 'KeyHolder' The script (I'm making a 3D game using a box collider for the key) using System.Collections; using System.Collections.Generic; using UnityEngine; public class KeyHolder : MonoBehaviour { private List KeyList; private void Awake() { Debug.Log("Added Key: " + keyType); KeyList.Add(keyType); } public void RemoveKey(Key.KeyType keyType) { KeyList.Remove(keyType); } public bool ContainsKey(KeyHolder.KeyType keyType) { return KeyList.Contains(keyType); } private void OnTriggerEnter(Collider collider) { Key key = collider.GetComponent(); if (key != null) { AddKey(key.GetKeyType()); Destroy(key.GameObject); } } }

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    2 жыл бұрын

    @@scotttowers1759 You don't have anything called KeyType inside that class

  • @scotttowers1759

    @scotttowers1759

    2 жыл бұрын

    @@CodeMonkeyUnity I just followed you word for word, letter for letter. As I say I'm new to this

Келесі