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
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 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!
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!
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.
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!
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?
@@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 ....
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.
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
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
@@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
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.
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.
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.
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.
@@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
@@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.
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.
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.
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?
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
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 TH-cam $170m, because of how they violated the Children's Online Privacy Protection Act (COPPA). TH-cam basically collects data on people on TH-cam, 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.
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
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 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 ?
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
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😅
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 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?
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
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
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 ?
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?
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
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
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.
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!
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 < keyList.Count; 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
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...
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.
@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!!!
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
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 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();
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?
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.
@@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.
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
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
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.
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
@@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 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"
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.
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 th-cam.com/video/pD27YuJG3L8/w-d-xo.html
@@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 :)
@@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); } } }
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
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
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.
@@christianmccauley7340 it should show in the included readme.
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.
Thanks!
@@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!
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.
I've been waiting for a video like this
Also thanks for the game bundle! Just picked it up and will surely check out all your titles.
This helped a lot with my burglar escape game! Thank you
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!
Thank you! 👍👍
This is so helpful! The way you explained help me understand how to read and apply the code better. Thank you so much!
:D
Awesome! I'm glad to hear it!
tysm yours is the only tutorial thats worked for me and im crunching for a school project T_T
Nice and clean coding! So easy to follow along
You make awesome Unity tutorials
Awesome! This is exactly what I needed.
Awesome tutorial!
I can't find in your channel this sprite outline 2D Shader Graph video.
Me neather
Yeah I've made the effect but haven't finished the video yet, should hopefully be out on Sunday.
@@CodeMonkeyUnity i will use in my game, can't wait!
@@CodeMonkeyUnity Thanks :)
Here's the Sprite Outline effect:
th-cam.com/video/FvQFhkS90nI/w-d-xo.html
This video was extremely helpful, thank you so much!
I'm glad to hear it! Thanks!
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.
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.
quick and simple, nice work
Check out the complete FPS Microgame Playlist for more Tutorials
th-cam.com/play/PLzDRvYVwl53sQhBZF00eC3SW09HJivZMH.html
Perfect, thank you 👍
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!
What took you so long to make this kind of tutorial?!! Great stuff tho, as usual.
Hippity hoppity your code is now my property
I hope it helps! Best of luck with your game!
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?
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 ......
That's an interesting topic, I'll look into it.
@@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 ....
you make awesome videos and you have helped me alot:)
but can you do videos about 2d platformers that would help me alot.
I've done a few and would definitely like to do more
th-cam.com/play/PLzDRvYVwl53sPOJQt-7Nb-a0n_XEcQotB.html
so how to make when we take the key, enter the door and get the star.... a sound playing?
Check out this video on a Simple Sound Manager: th-cam.com/video/QL29aTa7J5Q/w-d-xo.html
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.
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
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
@@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
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.
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.
Yeah that's tricky, always be very careful with misplaced ;
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.
I have the Error : Assets/Key.cs(7,17): error CS0102: The type `Key' already contains a definition for `keytype'
can you Help me ?
Sounds like you defined two types with the exact same name.
@@CodeMonkeyUnity I dont think so, but i find no mistake
I found it, in the part of the [SerializeField] private KeyType keyType;
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.
Add some Debug.Log to see what your code is doing, and make sure all collisions are working correctly th-cam.com/video/Bc9lmHjqLZc/w-d-xo.html
@@CodeMonkeyUnity According to my Debug.Log everything works as your video says it does. My doors (which are animated) don't stop opening & closing.
@@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
@@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.
@@CodeMonkeyUnity I got it dude you're the man. Thank you.
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.
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!
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.
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.
this is also possebel for 3d games right not only 2d?
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?
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
Is there a way to use this in a 3D game.
Of course, the underlying system doesn't care if the door is a sprite or a 3D mesh th-cam.com/video/3zxTigjJr24/w-d-xo.html
would this typr of coding work on something like the fps microgame in unity?
Sure, there's nothing here that is specific to any game genre
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 TH-cam $170m, because of how they violated the Children's Online Privacy Protection Act (COPPA). TH-cam basically collects data on people on TH-cam, 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.
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
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
same problem!
@@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 ?
solved it: change keyTemplate.gameObject.SetActive(true); to - > keyTransform.gameObject.SetActive(true);
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 ?
I've just posted a video on multiple ways of interacting with doors
th-cam.com/video/BJ4bNFPuDWA/w-d-xo.html
Combine the Key with the Button method.
@@CodeMonkeyUnity can you make a video about using raycast to interact about door and key in 3d game pls ? Its would be awsome
Great! But how did you made doors animation?
Using Unity's Animator, its very simple just Open and Close.
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
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😅
How to make it so the key only works if it has a parent (for example: hand) and the key is active?
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?
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
@@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?
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
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
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
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 ?
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?
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
A curious question, if i want it to have a inventory limit, should I use array instead of list?
You can use either of them, just check either array.Length or list.Count
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??
Maybe use an Interface to interact with objects
th-cam.com/video/BJ4bNFPuDWA/w-d-xo.html
th-cam.com/video/MZOrGXk4XFI/w-d-xo.html
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
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.
Does this work for 3D games?
I dunno
Question: how to set up post processing after import the asset, i always got null for ambientocclusion
Can we pick up multiple keys at once??
Sure, the code uses a List to store them.
@@CodeMonkeyUnity Thanks!! You are great.
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!
I'm having the same issue null error
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 < keyList.Count; 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
same problem, how did you fixed it?
same here, did you solved it?
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...
Make sure you're not mixing the keyTemplate and keyTransform. The template should only be used for cloning.
@@CodeMonkeyUnity yeah, i understood it yersterday and fixed it. Thanks for your answer!
How did you fixed it ? I still can't understand
[Edit]
i just change in line 39 from "keyTemplate" to "keyTransform" and it fixed.
@@lolsplaying6629 Thanks friend
@@lolsplaying6629 oh my god you're literally a life saver thank you so much
how did you do the door animation? can you show a mini guide?
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.
thanks!)
In fps micro game it says keydoorsystem_player.cs is giving a warning saying it's not assigned how to fix this
where's the 3d one? very good tutorial by the way
The logic is all the same, only difference is using 3D components unitycodemonkey.com/video.php?v=3zxTigjJr24
@@CodeMonkeyUnity Thanks!
how to do the animation for opening the door?
How do i make the door require multiple keys to open?
For example: Door 1 requires (Green and Red Key)
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.
@@CodeMonkeyUnity Does that mean making an array or smth else?
@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!!!
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
@@CodeMonkeyUnity alright, how do i change it? and how do i find which one i'm using? sorry im a noob at unity
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.
What is on line 27?
@@CodeMonkeyUnity Key key = collider.GetComponent();
@@davidconner1028 The collider property is no longer used, do gameObject.GetComponent()
To get the key just do gameObject.GetComponent()
@@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();
@@davidconner1028 i have the same problem did you find a solution ?
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?
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.
@@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.
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
Is your collision triggering? th-cam.com/video/Bc9lmHjqLZc/w-d-xo.html
I cant open the package in unity all color pink... can you guys help me..
Run the URP material upgrader
@@CodeMonkeyUnity Thank you so much for replying but im new to this can i ask where is the URP material upgrader?
can you make a video of this in the unity FPS microgame so I dont need to try and switch between 2d and 3d
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
@@CodeMonkeyUnity thanks you are the best
how to add animation to door
Just like you add an animation to anything. Add an Animator, create an animation
when will you do crafting system
It's on my list
Does this work for a 3D game bro?
Yes, just replace the sprites with 3D meshes th-cam.com/video/3zxTigjJr24/w-d-xo.html
Does this work with 3D aswell?
Yes, the system doesn't care if your door is a Sprite or a Mesh
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
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.
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
My key in the UI did not disappear even after I used my key. Where did I do wrong?
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
@@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.
@@thescarblaze1061 So was the log triggered or not? Sounds like the key is being destroyed but your UI is not listening to that event.
Does this work for a 2D Platformer too?
Sure, the logic doesn't care how the sprites are drawn
Okay thanks ^_^
U‘r great and I learned many things from you
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.
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
@@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"
@@pelethehedgehog9444 Means youre trying to access an object that is set to null
I'm korean! Thank you!
Does this work in 3d?
Yes, the visuals are separate from the logic so you can use Meshes instead of Sprites
@@CodeMonkeyUnity Thank You!
Please more tutorials for micro fps
, like multiple weapons with animations, Or flying enemies like helicopter from half life 2
How can i use "using.CodeMonkey" in my script? please help
Download the Utilities and double click the UnityPackage to add it to your Project.
After Last!!! xD
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.
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 th-cam.com/video/pD27YuJG3L8/w-d-xo.html
Gunpoint mechanics
Copied word for word and get a whole host of errors :(
What errors? Step one is identify what actually is the problem th-cam.com/video/5irv30-bTJw/w-d-xo.html
@@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 :)
@@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);
}
}
}
@@scotttowers1759 You don't have anything called KeyType inside that class
@@CodeMonkeyUnity I just followed you word for word, letter for letter. As I say I'm new to this
First
Last
Second
After last
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