For anyone having issues with score display not changing, check if your player object has the tag "Player" selected. It was mentioned in the video but somehow I missed it multiple times, it was driving me insane. My player object was named "Player" so that is why I missed it, it has to be a TAG. :) Also, make sure that you drag your text mesh to the score manager object (text field). Great tutorial btw, thanks! :D
If anyone comes from watching brackeys, how to animate and player movement 2D games or you just use two colliders in your player object and sometimes when you collect a coin the games counts it as two, you could try to reduce the size of the top collider, which is used so you player can crouch, in a way that stays in the same Y offset so your player objetc wont go trough a roof platform without crouching. This worked for me, hopefully it does for you too.
THIS TUTORIAL SAVED MY LIFE!! So well thought out I had no errors in my script. You did go fast for a beginner but that's fine, I just put the video at 0.5 speed to follow along in Unity. Thank you for making this!
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
If You Dont Want It To Add And X Infront Of The Score Value Text Then Just Remove The: "X" + On Line 24 // if you wanna copy paste public void ChangeScore(int coinValue) { score += coinValue; text.text = score.ToString(); } }
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
6:38 I like how you mention the rect transform/anchor so that it fits well in different screen sizes. A lot of tutorials dont mention this. Liked and subscribed. Hope you keep making more Unity 2D videos. Cheers man. :)
(Good Tutorial-THX)For everyone who has problem with score (ui display) changing. I had this problem also, "0" was displaying all the time... I read all comments here , but nothing helps... in my case it was "mistake autofilling in VS" i whant type " private void OnTriggerEnter2D but it automaticly fill normal one "private void OnTriggerEnter" ( for 3D not 2D, and that's not worrking couse 2d object can't collide with 3d one). It's realy simple mistake, but sometimes it could be hard to find. Then if you check all thinngs with TAG's etc. check if all methods are correct. And after that, if you will still have problem, just type something like this: Debug.Log(" +1 coin"); in methods who are involved in coin counting( coin.cs in my case). Play the game and pause it after collecting coin and check Console (in unity), if "+1 coin" not displaying there then something must be wrong... and basicly its how you should search for errors and faults.... I m also begginer in that but that could help in plenty of diffrent situation's,atleast worth of try. Good Luck.
I get a really weird error and i was sifting through the comments and it doesnt look like others are having the same problem... NullReferenceException: Object reference not set to an instance of an object ScoreManager.ChangeScore (System.Int32 coinValue) (at Assets/Scripts/ScoreManager.cs:25) Coin.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Coin.cs:14) Ive done exactly everything youve done (that i know of, ive gone over the video several times) and im not sure what to do to fix it! please help!!!
how would you keep the coin value increasing. like for saving money to buy thing in a in game shop my coins value reset every level and every time i start a new game???
I’ve been going insane I downloaded visual studio 2017 a while back and just thought there was something wrong with my computer and that’s why I was getting nothing but errors but now I know it’s because I download the freaking 2017 edition I’m i’m literally so mad I downloaded the 2019 version and now I’m good 😞
Its very simple Here are the changes: using UnityEngine.ui - instead of using TMPro public Text text - instead of public TextMeshProUGUI That should solve the problem.
bro how to resolve null reference exception object reference not set to an instance of an object because we wre using new versions of unity and we are not able to use text box plain instead we are using text mesh pro text after importing tmp tools
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
I had an issue with this where the colliders where registering but the coin wasnt destroying its self (this is due from hopping between tutorials because i couldnt find a complete 2d course) anyway the solution is to check that your colliders on your collectables are set to as trigger.
turns out its the Trail Renderer component at the editor, you can add it and set length + color. If your Trail Renderer gives a bright pink afterimage, you need to go to it's "Materials" section and add a material to "Element 0".
@@noodleface9975 Yes, I was going to answer that hahaha. You can see on the video also. Good job figuring that out and sharing here!!! Thanks my friend :)
Thank you mate, that was so helpful, I woundn't have find out on my own, can you teach us how to do things like spikes traps and stuff like that ? Sorry for my bad English.
Hi Jean, No need to be sorry, your English is perfect. Yes I can, I have few other tutorials on the way but I will put that on my list and soon I will release. :) Thanks for watching
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
i really like the tutorial but i have one question. Why doesnt it work in all scenes i added the scoremanager, the canvas, and a coin? would by great if you could help me :)
Hey F., So you mean that your score comes back to 0 when you change scenes is it ? For that you need a score manager that will follow you across the scenes. It's hard to explain here I would recommend you to have a look on something called dontdestroyonload. here is the link: docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html So your score manager wont be destroyed once you move on to the next level
So I had this problem: for some reason when I had instance = this; in my script, public TextMeshProUGUI text; didnt work. When I removed instance = this; from the script then public TextMeshProUGUI text; started working but there was object reference missing so I added it back and it worked perfectly. Not sure why it didnt work in the 1st place but hopefully this might help some people. Thanks for the tutorial. :)
Hi, our ScoreManager scripts are identical but I get the compiler error in Unity. I used both UnityEngine.UI and TMPro, but it still does not work . help?
@@lanayaassasin5373 I have the same problem but I don't get a compiler error. Here is my ScoreManager script: using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class ScoreManager : MonoBehaviour { public static ScoreManager instance; public TextMeshProUGUI text; int score; // Start is called before the first frame update void Start() {
if (instance == null) { instance = this; } } public void ChangeScore(int coinValue) { score += coinValue; text.text = "x" + score.ToString(); } } And Here is my Coin script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Coin : MonoBehaviour { public int coinValue = 1; private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("Player")) { ScoreManager.instance.ChangeScore(coinValue); } } }
Thank you for your tutorial! My I ask you why my score stops to 1 even if I duplicated my coin? I made a total of three of them but when I catch the second one, the score disappears
Hello! thanks for video but ı have a question The script is working but when my player die and game start again the coins is not here what ı need to do
I got everything working but I have a strange problem. Sometimes when I pick up a coin, the score counts it as two coins. Anyone else experience this? It happens very inconsistently.
maybe instead of using 2 colliders of which im assuming is a square and a circle because that is also what im using lol, maybe a capsule collider? its not perfect but it will do the job
Hey Mate, loved the video however ive had a problem right at the last step im getting an error. NullReferenceException: Object reference not set to an instance of an object Coin.OnTriggerEnter2D Any thoughts?
If you still passing the coins, it might be that the player and the coins are not colliding. Check if the Collision methods are ok and if you applied the tags correctly.
ok so I'm having an issue where the player touches the coin and sometimes 2 coins are added when I touch only 1. The only thing that I can see affecting this could be the colliders I have set up on my player (box on the head and circle on the bottom)
Hey mate yes you are correct it is to due with having the two colliders as both colliders are hitting the cherry at once and causing the coinScore to go up twice instead of once :)
bro I have make a game and your video see that and collect coins same to your video usey game but collect coin is palye but score is not increase plz solution me I am a Indian so my English language is poor sorry.
Great video, I've added the coins and everything works perfectly. Good explanation, everything has logic in it... subscribed and liked! If you need suggestions for other videos, I've got ideas :P And 1 question after all - how can I code that the counter goes back to 0 when my char dies? I've tried a couple of things, but I'm afraid my code so far is too messy to make it work. Once again, thank you a lot!
Hi Luka, Thank for like and sub, I appreciate it. :) Could you show me how are you doing to save the coins you collect ??? How are you doing to store the information of the coins collected ??? Thanks :)
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
I really appreciate your videos, Liked and Subscribed. I have a code question though, I entered script as you did - but got a compiler error. Not sure if I have a different version (I'm new to coding). But also realized when I type Collider2D, it doesnt appear as a link or colored; Ive noticed this with other parts of tutorials as well. Any suggestions?
great tutorial but i was stuck on the script part since i dont know where to put the void onEnterTrigger2d since my playercontroller script is different to yours i'm a beginner and i dont know if this was made for beginners or not but, overall great video :)
thx man for this tutorial...now i put them into game scene , what about showing the score count of coins with main menu scene and shop scene too to buy items ? because all of there are not in the same scene !...
Hi Ahmed, That's a good idea for a tutoria, it can be made in a very different ways. Once I go forward with the 2d tutorials I will show a way to do that. Thanks for the recommendation.
@Xlaugts, are you still supporting this? Your scripts are working fine and they are also easy to understand. My only issue and I guess it comes from animation, is, that my score is raising from 1 - 4 randomly (I am using 4 grapihcs for a gem animation). Any suggestion how to solve this issue?
I have a question. I did everything you did with the coin and for some reason I go right through it. Any ideas? Never mind I put on collision instead of ontrigger 😅
Hey i know this tutorial is relative old but i want to ask about saving this data (coins) and use it later to buy things from the menu?, i want to use player.prefs but everyone says that is bad, (purchase in the app) soo i really want if you can help me and do a tutorial of this! Great video Work for me, keep the great work!
@@xlaugts151 yes, because I have "Collectable objects and Interactable" and I want create a condition if the player collide a collectable object and if it's a Coin with tag for example. Like I'm a noob
@@Magma-uw7yo You have to have a variable called "public Layermask layer;" you change the value of this on the inspector of the gameObj this script is attached. Than you can use this to compare. Have a look on this answers.unity.com/questions/422472/how-can-i-compare-colliders-layer-to-my-layermask.html see if you can understand it will show u how to compare them
Hello friend, the scrips compile me without problem, the coins disappear correctly but it does not count me in the marker, I have everything fine, so it could be
Great tutorial! I do have an issue though, because I use 2 colliders for my player (so it can crouch underthings) the coins sometimes count for 2 instead of 1. Anyone have a suggestion to fix it?
You have to go into the coins script and add the following: 1: add 'public bool trigger = false' inside of the coin class, but outside of the OnTriggerEnter2D method. 2: inside the OnTriggerEnter2D method, inside the if(other.gameObject.CompareTag("Player") statement, add another if condition to if (trigger == false) and execute the ScoreManager inside of that. Remember to set trigger to true so your script only loops once. This essentially just creates an internal condition that gets checked and prevents any single coin from being counted twice.
@@doctordoge5058 I watched this video and made the coin system twice because of the duplication of coins. Then i came here and found your comment. Thank you!
The script worked...... until i died and reloaded the scene so basicaly it works on the first try and if i manualy reload it (pressing play button) but if i use the script to reload the scene it dousent count the coins
Hi this works but how do i permanently destroy it? Since I'm going from and to different scenes/levels, but whenever I come back to the scene/level the collectable is still there. Is there any way of destroying it forever?
if you only want to use one sprite, you can just use this script. Isn't as visually pleasing, but much easier! using System.Collections; using System.Collections.Generic; using UnityEngine; public class CoinRotation : MonoBehaviour { private Vector2 rotation; // Start is called before the first frame update void Start() { rotation = new Vector2(0, 1); } // Update is called once per frame void Update() { transform.Rotate(rotation); } }
hi thank you so much for the video it helps me a lot :) I just need help on one thing. Why is it when I collect a coin the score becomes 2 instead of 1?
hey mate you might've fixed this by now but this is due to having multiple collision boxes touching the cherry at the same time, to fix it you may have to fiddle around with your characters collision :)
For anyone having issues with score display not changing, check if your player object has the tag "Player" selected. It was mentioned in the video but somehow I missed it multiple times, it was driving me insane. My player object was named "Player" so that is why I missed it, it has to be a TAG. :) Also, make sure that you drag your text mesh to the score manager object (text field). Great tutorial btw, thanks! :D
Great job!!! Yes, small mistakes can drive us crazy sometimes hahaha....
If anyone comes from watching brackeys, how to animate and player movement 2D games or you just use two colliders in your player object and sometimes when you collect a coin the games counts it as two, you could try to reduce the size of the top collider, which is used so you player can crouch, in a way that stays in the same Y offset so your player objetc wont go trough a roof platform without crouching. This worked for me, hopefully it does for you too.
THIS TUTORIAL SAVED MY LIFE!! So well thought out I had no errors in my script. You did go fast for a beginner but that's fine, I just put the video at 0.5 speed to follow along in Unity. Thank you for making this!
Thanks a lot man 😊😊❤️ it's been 3 years since you published this video and it's still working.... I really do appreciate it 🙏🏿
For those who already followed but the Player just go through the coin.
Check your coin collider and check mark the "Is Trigger" box.
I'm glad I found this tutorial as I needed to finish my coursework so this was a big help
Hi brother
can i get that game file?
BARON_IFD i also need that game file to finish my course work can u help me ..its fucking hard bro🥺
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
If You Dont Want It To Add And X Infront Of The Score Value Text Then Just Remove The: "X" + On Line 24
// if you wanna copy paste
public void ChangeScore(int coinValue)
{
score += coinValue;
text.text = score.ToString();
}
}
Note; the player sprite has to be a collider too. Being a rigidbody only is not enough.
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
thanx broo...you are a life saver...within 30 mins..its working..you are the best.!! May god bless u and your family.
After watching all other video about how to display Score, i couldn't able to display score via textmesh pro , this video is only a Savior.
Hahaha than Deeze!
really good video but for me as a beginner this was a bit fast and i found myself having to pause every 10 secconds.
Thanks for the feedback, I notice that the tutorials was a bit fast.
Good to know, that way I can improve that for the next ones
Lol xlaughs
Then ur really slow w/ stuff cus for me this tutorial was great and way easier to understand and follow than any other I've seen.
I generally pause every so often when following tutorials anyway to make sure i'm doing everything right..
It was the slowest video in unity that I found... if you just copy code you won't learn
6:38 I like how you mention the rect transform/anchor so that it fits well in different screen sizes. A lot of tutorials dont mention this. Liked and subscribed. Hope you keep making more Unity 2D videos. Cheers man. :)
can i get the game file😔
(Good Tutorial-THX)For everyone who has problem with score (ui display) changing. I had this problem also, "0" was displaying all the time... I read all comments here , but nothing helps... in my case it was "mistake autofilling in VS" i whant type " private void OnTriggerEnter2D but it automaticly fill normal one "private void OnTriggerEnter" ( for 3D not 2D, and that's not worrking couse 2d object can't collide with 3d one). It's realy simple mistake, but sometimes it could be hard to find. Then if you check all thinngs with TAG's etc. check if all methods are correct. And after that, if you will still have problem, just type something like this: Debug.Log(" +1 coin"); in methods who are involved in coin counting( coin.cs in my case). Play the game and pause it after collecting coin and check Console (in unity), if "+1 coin" not displaying there then something must be wrong... and basicly its how you should search for errors and faults.... I m also begginer in that but that could help in plenty of diffrent situation's,atleast worth of try. Good Luck.
Thank you so much
Thank you so much now i made own first game
dude this is sooooooo good this helped me out alot and you explaind everything how i wanned you to do and it was simple and works
If anybody has an issue where the item counter goes up by 2, for me it worked to increase the triggrer collider's radius so try that
are you refering to edge radius? because for me it still goes up by 2 times the value
I get a really weird error and i was sifting through the comments and it doesnt look like others are having the same problem...
NullReferenceException: Object reference not set to an instance of an object
ScoreManager.ChangeScore (System.Int32 coinValue) (at Assets/Scripts/ScoreManager.cs:25)
Coin.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Coin.cs:14)
Ive done exactly everything youve done (that i know of, ive gone over the video several times) and im not sure what to do to fix it!
please help!!!
You just got a new subscriber!
Really good fast tutorial, helped me a lot, thank u
how would you keep the coin value increasing. like for saving money to buy thing in a in game shop my coins value reset every level and every time i start a new game???
See Brackeys "Save/Load in Unity" video by 'Brackeys'
very straightforward and easy to follow. thank you
Great tutorial!
Could you make a tutorial can buy new stuff with theese coins using player prefs?
I’ve been going insane I downloaded visual studio 2017 a while back and just thought there was something wrong with my computer and that’s why I was getting nothing but errors but now I know it’s because I download the freaking 2017 edition I’m i’m literally so mad I downloaded the 2019 version and now I’m good 😞
Thank you for the lesson. He was very helpful to me!!!
What to write in the script if i used text instead of textmeshpro?
Its very simple
Here are the changes:
using UnityEngine.ui - instead of using TMPro
public Text text - instead of public TextMeshProUGUI
That should solve the problem.
@@xlaugts151 Thank You
thank you so much for this, you saved my life!!
Great tutorial! Everything worked perfectly, however, I was wondering if there was a way to save your coin counter from scene to scene?
Do you know how to do it now
pretty sure you use something called player prefs this saves data such as audio volume and etc so they can be used in other scene. Look into it.
bro how to resolve null reference exception object reference not set to an instance of an object
because we wre using new versions of unity and we are not able to use text box plain instead we are using text mesh pro text after importing tmp tools
Thank you man, this help me a lot with my game. GG!
Thanks bro!
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
Thank you for the video, it helped me a lot to complete the final assignment!!
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
I had an issue with this where the colliders where registering but the coin wasnt destroying its self (this is due from hopping between tutorials because i couldnt find a complete 2d course)
anyway the solution is to check that your colliders on your collectables are set to as trigger.
how did you make the afterimage behind the santa
turns out its the Trail Renderer component at the editor, you can add it and set length + color. If your Trail Renderer gives a bright pink afterimage, you need to go to it's "Materials" section and add a material to "Element 0".
@@noodleface9975 Yes, I was going to answer that hahaha. You can see on the video also. Good job figuring that out and sharing here!!! Thanks my friend :)
Thank u my friend , worked perfectly
Thanks Strider
Do you have a Tutorial on how to reset the coin whenever scene is restarted?
Great tutorial thank you so much for making it!
Thank you mate, that was so helpful, I woundn't have find out on my own, can you teach us how to do things like spikes traps and stuff like that ? Sorry for my bad English.
Hi Jean,
No need to be sorry, your English is perfect.
Yes I can, I have few other tutorials on the way but I will put that on my list and soon I will release. :)
Thanks for watching
@@xlaugts151 Thank you, I'm looking foreward To see the others tutorial !
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
How do I make it save for levels
i really like the tutorial but i have one question. Why doesnt it work in all scenes i added the scoremanager, the canvas, and a coin?
would by great if you could help me :)
Hey F.,
So you mean that your score comes back to 0 when you change scenes is it ?
For that you need a score manager that will follow you across the scenes.
It's hard to explain here I would recommend you to have a look on something called dontdestroyonload.
here is the link:
docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
So your score manager wont be destroyed once you move on to the next level
@@xlaugts151 , Thank you, I was searching for this for ages!
how do I add a dontdestroyonload to this?
Hey i did everything on the video and everything works except the counter, it still shows 0 help plz
That might be because of your score Manager is not counting the coins
coinValue = 1;
me too, this tutorial is shit
Just what I needed. Thanks!
I've got everything identic but when I pick a coin it stays to 0
I'm having same issue, no errors but stays at 0
Absolutely amazing. thanks alot.
good vid mate big thanks
Thanks Ma Red :)
Thank you so much keep up the work.
Thank you soooo much it worked perfectly!!!! :)
Thanks you DuckMaster
So I had this problem:
for some reason when I had instance = this; in my script, public TextMeshProUGUI text; didnt work. When I removed instance = this; from the script then public TextMeshProUGUI text; started working but there was object reference missing so I added it back and it worked perfectly. Not sure why it didnt work in the 1st place but hopefully this might help some people. Thanks for the tutorial. :)
Hi, our ScoreManager scripts are identical but I get the compiler error in Unity.
I used both UnityEngine.UI and TMPro, but it still does not work . help?
What it says in the compiler error? Please copy and paste here
@@lanayaassasin5373 I have the same problem but I don't get a compiler error.
Here is my ScoreManager script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ScoreManager : MonoBehaviour
{
public static ScoreManager instance;
public TextMeshProUGUI text;
int score;
// Start is called before the first frame update
void Start()
{
if (instance == null) {
instance = this;
}
}
public void ChangeScore(int coinValue) {
score += coinValue;
text.text = "x" + score.ToString();
}
}
And Here is my Coin script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Coin : MonoBehaviour
{
public int coinValue = 1;
private void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.CompareTag("Player")) {
ScoreManager.instance.ChangeScore(coinValue);
}
}
}
thank you so much for the tutorial... how to create particle when jump?
I know it’s late but you can make the particles a prefab and instantiate it at the position of the character
@@nicolaifeldthaus4649 thank you for the late respons... ^_^
I already have a OnTriggerEnter2D made so it won't let me make another one, but the code wont work if I put it into my already made function
Hey Casey,
Which script are you trying to make another OnTriggerEnter2D function ???
same problem, do you already finds the solution
thank you for the tutorial!!
Thank you for your tutorial! My I ask you why my score stops to 1 even if I duplicated my coin? I made a total of three of them but when I catch the second one, the score disappears
Awesome, thanks!
thx so much for the video
Hello! thanks for video but ı have a question
The script is working but when my player die and game start again the coins is not here what ı need to do
I got everything working but I have a strange problem. Sometimes when I pick up a coin, the score counts it as two coins. Anyone else experience this? It happens very inconsistently.
It's because you probably have a player with 2 colliders (like in Brackeys tutorial), I have this problem too and I haven't find a solution yet...
@@KandaOneiros Oh shit this makes total sense
maybe instead of using 2 colliders of which im assuming is a square and a circle because that is also what im using lol, maybe a capsule collider? its not perfect but it will do the job
@@jesstrueit2563 I resolved the problem using the counter code not on the coin but on the player (or viceversa, I don't remember now)
Hey Mate, loved the video however ive had a problem right at the last step im getting an error.
NullReferenceException: Object reference not set to an instance of an object Coin.OnTriggerEnter2D
Any thoughts?
Hi Jono,
Is that error point to any specific part of your code ???
Thanks for watching
Cheers
@@xlaugts151 i have the same problem, its refering to this part of the code:
text.text = "X" + score.ToString();
same here
Great video, keep going man
I have a problem. When I walk and collect coin I get the same value as I set but when I jump on a coin the value doubles. How to fix?
good job brother thanks
I did everything just like in the video but i still pass threw the coin i need help
same
If you still passing the coins, it might be that the player and the coins are not colliding.
Check if the Collision methods are ok and if you applied the tags correctly.
@@xlaugts151 I did the same but I did the script on the coin instead of the player and it somehow worked
You did not give to the player the player TAG
it works but my game pauses every time i collect any coins and the counter doesn't work
ok so I'm having an issue where the player touches the coin and sometimes 2 coins are added when I touch only 1. The only thing that I can see affecting this could be the colliders I have set up on my player (box on the head and circle on the bottom)
Hey mate yes you are correct it is to due with having the two colliders as both colliders are hitting the cherry at once and causing the coinScore to go up twice instead of once :)
thanks man this helped me
It Isn't Updating The Score Counter
your video is awesome bro ...
Thank you Chandrajitsinh!
If you have any suggestion let me know :)
bro I have make a game and your video see that and collect coins same to your video usey game but collect coin is palye but score is not increase plz solution me I am a Indian so my English language is poor sorry.
Great video, I've added the coins and everything works perfectly. Good explanation, everything has logic in it... subscribed and liked!
If you need suggestions for other videos, I've got ideas :P
And 1 question after all - how can I code that the counter goes back to 0 when my char dies? I've tried a couple of things, but I'm afraid my code so far is too messy to make it work.
Once again, thank you a lot!
Hi Luka,
Thank for like and sub, I appreciate it. :)
Could you show me how are you doing to save the coins you collect ???
How are you doing to store the information of the coins collected ???
Thanks :)
CAN SOMEONE PLEASE GIVE ME THE SCRIPTS!!!! I HAVE BEEN WORKING ON THIS FOR 5 HOURS AND I KEEP GETTING A COINVALUE DOESNT EXIST IN CURRENCT CONTEXT ERROR PLEASE I NEED SOMEONES HELP!!!!!!!!
how do you save coin count between sense
Any ideas why bouncy material on my coins is adding jumping force with every bounce?
Mihovil,
Is the coin bouncing higher each time?
@@xlaugts151 That is correct.
I really appreciate your videos, Liked and Subscribed. I have a code question though, I entered script as you did - but got a compiler error. Not sure if I have a different version (I'm new to coding). But also realized when I type Collider2D, it doesnt appear as a link or colored; Ive noticed this with other parts of tutorials as well. Any suggestions?
great tutorial but i was stuck on the script part since i dont know where to put the void onEnterTrigger2d since my playercontroller script is different to yours
i'm a beginner and i dont know if this was made for beginners or not but, overall great video :)
Where would I put this in my custom script? I just need to put this in my current script about the object destroying part.
and how d you save the coins? for like a shop or something
thx man for this tutorial...now i put them into game scene , what about showing the score count of coins with main menu scene and shop scene too to buy items ? because all of there are not in the same scene !...
Hi Ahmed,
That's a good idea for a tutoria, it can be made in a very different ways.
Once I go forward with the 2d tutorials I will show a way to do that.
Thanks for the recommendation.
Good video Duude...
great tutorial thank you so much :))
Thank you
@Xlaugts, are you still supporting this? Your scripts are working fine and they are also easy to understand. My only issue and I guess it comes from animation, is, that my score is raising from 1 - 4 randomly (I am using 4 grapihcs for a gem animation). Any suggestion how to solve this issue?
Why when I duplicate the counter(TMP), then it not count coins in second one?
Can somebody help me please?
thanks, its working
Anyway for me to keep the coins bouncing up and down?
my Text variable is public but in unity it doesn't appears the drag and drop to set Text value
Thanks man!
thanks man
Cannot drag text onto the script slot. just wont let me, not for TMPro or regular text
I have a question. I did everything you did with the coin and for some reason I go right through it. Any ideas? Never mind I put on collision instead of ontrigger 😅
Oh, Congratulation my friend.
Good job and thanks for watching
Maybe because you forget to give the coin a Collider. and if you already put the collider, maybe you forget to check the "Is Trigger" box
I did the same mistake and didnt get it fixed for a while, so thaks for ur comment u helped me find the error
Hey i know this tutorial is relative old but i want to ask about saving this data (coins) and use it later to buy things from the menu?, i want to use player.prefs but everyone says that is bad, (purchase in the app) soo i really want if you can help me and do a tutorial of this! Great video Work for me, keep the great work!
did u find anything for this? I need the same thing that u wrote :)
No, but use player prefs is way more simple
see Save/Load in Unity by Brackeys
he uses binary System which is very easy to make and very secure than player Prefs and Json, XML file
hi, how can I find Layer name with game Object ?
Hi Magma,
Do you want to find a layer using code ?
@@xlaugts151 yes, because I have "Collectable objects and Interactable" and I want create a condition if the player collide a collectable object and if it's a Coin with tag for example. Like I'm a noob
@@Magma-uw7yo You have to have a variable called "public Layermask layer;" you change the value of this on the inspector of the gameObj this script is attached.
Than you can use this to compare.
Have a look on this answers.unity.com/questions/422472/how-can-i-compare-colliders-layer-to-my-layermask.html
see if you can understand it will show u how to compare them
super video can you help me, when i make a build the text doesnt show
Hello friend, the scrips compile me without problem, the coins disappear correctly but it does not count me in the marker, I have everything fine, so it could be
Thank you very much!!!
friend to me because when collecting the last coin the image and text are erased from the screen?
How can i save the score though??
Great tutorial! I do have an issue though, because I use 2 colliders for my player (so it can crouch underthings) the coins sometimes count for 2 instead of 1. Anyone have a suggestion to fix it?
You have to go into the coins script and add the following:
1: add 'public bool trigger = false' inside of the coin class, but outside of the OnTriggerEnter2D method.
2: inside the OnTriggerEnter2D method, inside the if(other.gameObject.CompareTag("Player") statement, add another if condition to if (trigger == false) and execute the ScoreManager inside of that. Remember to set trigger to true so your script only loops once.
This essentially just creates an internal condition that gets checked and prevents any single coin from being counted twice.
@@doctordoge5058 i can't do this please help me
can you help me?
@@doctordoge5058 Thanks a lot. Had trouble with that. checked the unity forums but couldn't find it there
@@doctordoge5058 I watched this video and made the coin system twice because of the duplication of coins. Then i came here and found your comment. Thank you!
The script worked...... until i died and reloaded the scene
so basicaly it works on the first try and if i manualy reload it (pressing play button) but if i use the script to reload the scene it dousent count the coins
thank you!!!
Hi this works but how do i permanently destroy it? Since I'm going from and to different scenes/levels, but whenever I come back to the scene/level the collectable is still there. Is there any way of destroying it forever?
what does it mean by "other.gameObject"?
it means the game object of the thing you are colliding with, in this case "other.gameObject" is the coin, because you are colliding with it
if you only want to use one sprite, you can just use this script. Isn't as visually pleasing, but much easier!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoinRotation : MonoBehaviour
{
private Vector2 rotation;
// Start is called before the first frame update
void Start()
{
rotation = new Vector2(0, 1);
}
// Update is called once per frame
void Update()
{
transform.Rotate(rotation);
}
}
hi thank you so much for the video it helps me a lot :) I just need help on one thing. Why is it when I collect a coin the score becomes 2 instead of 1?
hey mate you might've fixed this by now but this is due to having multiple collision boxes touching the cherry at the same time, to fix it you may have to fiddle around with your characters collision :)
Can i get the game file for my assignment😔