Unity 2D Collecting Coins Tutorial

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 284

  • @mihovilmikulec
    @mihovilmikulec 5 років тому +7

    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

    • @xlaugts151
      @xlaugts151  5 років тому +1

      Great job!!! Yes, small mistakes can drive us crazy sometimes hahaha....

  • @arturoescobar4226
    @arturoescobar4226 2 роки тому +2

    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.

  • @JH-bd5bt
    @JH-bd5bt 4 роки тому +5

    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!

  • @codeDynastyStudios
    @codeDynastyStudios 2 роки тому

    Thanks a lot man 😊😊❤️ it's been 3 years since you published this video and it's still working.... I really do appreciate it 🙏🏿

  • @Mikeul2GT
    @Mikeul2GT 5 років тому +3

    For those who already followed but the Player just go through the coin.
    Check your coin collider and check mark the "Is Trigger" box.

  • @baron_ird101
    @baron_ird101 4 роки тому +3

    I'm glad I found this tutorial as I needed to finish my coursework so this was a big help

    • @devdev554
      @devdev554 3 роки тому

      Hi brother

    • @devdev554
      @devdev554 3 роки тому

      can i get that game file?

    • @devdev554
      @devdev554 3 роки тому

      BARON_IFD i also need that game file to finish my course work can u help me ..its fucking hard bro🥺

    • @DScreationsRBLX
      @DScreationsRBLX 3 роки тому

      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!!!!!!!!

  • @itsdonix
    @itsdonix Рік тому +2

    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();
    }
    }

  • @ikjman1
    @ikjman1 4 роки тому +10

    Note; the player sprite has to be a collider too. Being a rigidbody only is not enough.

    • @DScreationsRBLX
      @DScreationsRBLX 3 роки тому +2

      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!!!!!!!!

  • @vigneshkadam3960
    @vigneshkadam3960 4 роки тому

    thanx broo...you are a life saver...within 30 mins..its working..you are the best.!! May god bless u and your family.

  • @deezero7103
    @deezero7103 5 років тому +2

    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.

  • @Hauki336
    @Hauki336 5 років тому +71

    really good video but for me as a beginner this was a bit fast and i found myself having to pause every 10 secconds.

    • @xlaugts151
      @xlaugts151  5 років тому +14

      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

    • @legendaryentertainment1490
      @legendaryentertainment1490 5 років тому

      Lol xlaughs

    • @dyl1562
      @dyl1562 4 роки тому +1

      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.

    • @kevschoen83
      @kevschoen83 4 роки тому +4

      I generally pause every so often when following tutorials anyway to make sure i'm doing everything right..

    • @blinkyoff
      @blinkyoff 4 роки тому

      It was the slowest video in unity that I found... if you just copy code you won't learn

  • @qqq9542
    @qqq9542 3 роки тому +2

    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. :)

    • @devdev554
      @devdev554 3 роки тому

      can i get the game file😔

  • @jinkutkay8838
    @jinkutkay8838 3 роки тому

    (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.

  • @trix7450
    @trix7450 4 роки тому +6

    Thank you so much now i made own first game

  • @itssushitime446
    @itssushitime446 4 роки тому +1

    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

  • @isellpeople
    @isellpeople 2 роки тому

    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

    • @MC-rn7xo
      @MC-rn7xo 2 роки тому

      are you refering to edge radius? because for me it still goes up by 2 times the value

  • @jesstrueit2563
    @jesstrueit2563 4 роки тому +3

    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!!!

  • @eclipseworldisaweeb1027
    @eclipseworldisaweeb1027 2 роки тому +1

    You just got a new subscriber!

  • @susanagomes585
    @susanagomes585 4 роки тому +1

    Really good fast tutorial, helped me a lot, thank u

  • @colechild-phillips7182
    @colechild-phillips7182 4 роки тому +5

    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???

    • @mitulmahish6145
      @mitulmahish6145 3 роки тому

      See Brackeys "Save/Load in Unity" video by 'Brackeys'

  • @ExtraKanin
    @ExtraKanin 5 років тому

    very straightforward and easy to follow. thank you

  • @fedechaotix
    @fedechaotix 5 років тому +4

    Great tutorial!
    Could you make a tutorial can buy new stuff with theese coins using player prefs?

  • @Johntron5443
    @Johntron5443 4 роки тому +2

    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 😞

  • @alexandrtodovyanskiy4051
    @alexandrtodovyanskiy4051 4 роки тому +1

    Thank you for the lesson. He was very helpful to me!!!

  • @dhrumangupta4583
    @dhrumangupta4583 5 років тому +5

    What to write in the script if i used text instead of textmeshpro?

    • @xlaugts151
      @xlaugts151  5 років тому +3

      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.

    • @edwardmartinson5247
      @edwardmartinson5247 4 роки тому

      @@xlaugts151 Thank You

  • @camilaortiz4490
    @camilaortiz4490 2 роки тому

    thank you so much for this, you saved my life!!

  • @logandessert9151
    @logandessert9151 3 роки тому +3

    Great tutorial! Everything worked perfectly, however, I was wondering if there was a way to save your coin counter from scene to scene?

    • @tejaskutal2922
      @tejaskutal2922 2 роки тому

      Do you know how to do it now

    • @karun7275
      @karun7275 2 роки тому

      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.

  • @varshask3231
    @varshask3231 2 роки тому +1

    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

  • @Gameoverpty
    @Gameoverpty 5 років тому +3

    Thank you man, this help me a lot with my game. GG!

    • @xlaugts151
      @xlaugts151  5 років тому

      Thanks bro!

    • @DScreationsRBLX
      @DScreationsRBLX 3 роки тому +1

      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!!!!!!!!

  • @owenchen3096
    @owenchen3096 5 років тому

    Thank you for the video, it helped me a lot to complete the final assignment!!

    • @DScreationsRBLX
      @DScreationsRBLX 3 роки тому

      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!!!!!!!!

  • @robertjones5130
    @robertjones5130 4 роки тому +2

    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.

  • @noodleface9975
    @noodleface9975 4 роки тому +1

    how did you make the afterimage behind the santa

    • @noodleface9975
      @noodleface9975 4 роки тому +1

      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".

    • @xlaugts151
      @xlaugts151  4 роки тому

      @@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 :)

  • @strider-s7101
    @strider-s7101 5 років тому +2

    Thank u my friend , worked perfectly

  • @lanayaassasin5373
    @lanayaassasin5373 3 роки тому +1

    Do you have a Tutorial on how to reset the coin whenever scene is restarted?

  • @animefanime11
    @animefanime11 3 роки тому

    Great tutorial thank you so much for making it!

  • @jeanbedry3941
    @jeanbedry3941 5 років тому +4

    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.

    • @xlaugts151
      @xlaugts151  5 років тому +1

      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

    • @jeanbedry3941
      @jeanbedry3941 5 років тому

      @@xlaugts151 Thank you, I'm looking foreward To see the others tutorial !

    • @DScreationsRBLX
      @DScreationsRBLX 3 роки тому

      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!!!!!!!!

  • @Blockhead-xc3dq
    @Blockhead-xc3dq 5 років тому +1

    How do I make it save for levels

  • @FBroz-uc6je
    @FBroz-uc6je 5 років тому +7

    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 :)

    • @xlaugts151
      @xlaugts151  5 років тому +3

      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

    • @ignuxas64
      @ignuxas64 5 років тому

      @@xlaugts151 , Thank you, I was searching for this for ages!

  • @emeralaxy850
    @emeralaxy850 5 років тому +2

    how do I add a dontdestroyonload to this?

  • @joaquinsebastianalbujacald8952
    @joaquinsebastianalbujacald8952 5 років тому +5

    Hey i did everything on the video and everything works except the counter, it still shows 0 help plz

    • @xlaugts151
      @xlaugts151  5 років тому +1

      That might be because of your score Manager is not counting the coins

    • @NickiAngel
      @NickiAngel 5 років тому +2

      coinValue = 1;

    • @ferdisauditore1469
      @ferdisauditore1469 4 роки тому +3

      me too, this tutorial is shit

  • @DieserJunge89
    @DieserJunge89 4 роки тому

    Just what I needed. Thanks!

  • @riouca
    @riouca 4 роки тому +2

    I've got everything identic but when I pick a coin it stays to 0

    • @elysian_dreams
      @elysian_dreams 3 роки тому

      I'm having same issue, no errors but stays at 0

  • @EnemyOTS
    @EnemyOTS 3 роки тому

    Absolutely amazing. thanks alot.

  • @aeli1413
    @aeli1413 5 років тому +2

    good vid mate big thanks

  • @yassgaming22
    @yassgaming22 4 роки тому

    Thank you so much keep up the work.

  • @CheekyBilly
    @CheekyBilly 5 років тому +2

    Thank you soooo much it worked perfectly!!!! :)

  • @MydasLP
    @MydasLP 2 роки тому

    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. :)

  • @JiffyVids
    @JiffyVids 3 роки тому +1

    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
      @lanayaassasin5373 3 роки тому

      What it says in the compiler error? Please copy and paste here

    • @muadhk
      @muadhk 3 роки тому

      @@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);
      }
      }
      }

  • @ustadzahofficial
    @ustadzahofficial 4 роки тому +1

    thank you so much for the tutorial... how to create particle when jump?

    • @nicolaifeldthaus4649
      @nicolaifeldthaus4649 4 роки тому

      I know it’s late but you can make the particles a prefab and instantiate it at the position of the character

    • @ustadzahofficial
      @ustadzahofficial 4 роки тому

      @@nicolaifeldthaus4649 thank you for the late respons... ^_^

  • @caseymckinney8377
    @caseymckinney8377 5 років тому +3

    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

    • @xlaugts151
      @xlaugts151  5 років тому

      Hey Casey,
      Which script are you trying to make another OnTriggerEnter2D function ???

    • @user-si8vn9jd3w
      @user-si8vn9jd3w 4 роки тому

      same problem, do you already finds the solution

  • @amb9401
    @amb9401 3 роки тому

    thank you for the tutorial!!

  • @alessiadidonna93
    @alessiadidonna93 Рік тому

    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

  • @OmeedNOuhadi
    @OmeedNOuhadi 2 роки тому

    Awesome, thanks!

  • @bobloyal8130
    @bobloyal8130 4 роки тому +1

    thx so much for the video

  • @bora6436
    @bora6436 4 роки тому +1

    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

  • @The5thAstronaut
    @The5thAstronaut 4 роки тому +2

    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.

    • @KandaOneiros
      @KandaOneiros 4 роки тому +2

      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...

    • @The5thAstronaut
      @The5thAstronaut 4 роки тому

      @@KandaOneiros Oh shit this makes total sense

    • @jesstrueit2563
      @jesstrueit2563 4 роки тому

      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

    • @KandaOneiros
      @KandaOneiros 4 роки тому

      @@jesstrueit2563 I resolved the problem using the counter code not on the coin but on the player (or viceversa, I don't remember now)

  • @Chafey14
    @Chafey14 5 років тому +3

    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?

    • @xlaugts151
      @xlaugts151  5 років тому

      Hi Jono,
      Is that error point to any specific part of your code ???
      Thanks for watching
      Cheers

    • @anantkhanna4954
      @anantkhanna4954 4 роки тому

      @@xlaugts151 i have the same problem, its refering to this part of the code:
      text.text = "X" + score.ToString();

    • @horajee5689
      @horajee5689 4 роки тому +2

      same here

  • @foefighter7066
    @foefighter7066 4 роки тому

    Great video, keep going man

  • @Vanduo610
    @Vanduo610 2 роки тому

    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?

  • @chakirniame3397
    @chakirniame3397 3 роки тому

    good job brother thanks

  • @adamfreedman5491
    @adamfreedman5491 5 років тому +3

    I did everything just like in the video but i still pass threw the coin i need help

    • @CRGMH
      @CRGMH 5 років тому +1

      same

    • @xlaugts151
      @xlaugts151  5 років тому

      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.

    • @adamfreedman5491
      @adamfreedman5491 5 років тому +1

      @@xlaugts151 I did the same but I did the script on the coin instead of the player and it somehow worked

    • @an_games_0437
      @an_games_0437 4 роки тому +1

      You did not give to the player the player TAG

  • @ratk1ngg
    @ratk1ngg 2 роки тому

    it works but my game pauses every time i collect any coins and the counter doesn't work

  • @jeffreynavarro5228
    @jeffreynavarro5228 4 роки тому +1

    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)

    • @TheZaru
      @TheZaru 4 роки тому +1

      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 :)

  • @xuyixz8229
    @xuyixz8229 4 роки тому

    thanks man this helped me

  • @ericgiant3821
    @ericgiant3821 4 роки тому +1

    It Isn't Updating The Score Counter

  • @chandrajitsinhparmar4242
    @chandrajitsinhparmar4242 5 років тому +2

    your video is awesome bro ...

    • @xlaugts151
      @xlaugts151  5 років тому

      Thank you Chandrajitsinh!
      If you have any suggestion let me know :)

    • @chandrajitsinhparmar4242
      @chandrajitsinhparmar4242 5 років тому +1

      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.

  • @LukaYuka1
    @LukaYuka1 5 років тому +2

    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!

    • @xlaugts151
      @xlaugts151  5 років тому

      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 :)

    • @DScreationsRBLX
      @DScreationsRBLX 3 роки тому +1

      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!!!!!!!!

  • @wynot7196
    @wynot7196 2 роки тому

    how do you save coin count between sense

  • @mihovilmikulec
    @mihovilmikulec 5 років тому +1

    Any ideas why bouncy material on my coins is adding jumping force with every bounce?

    • @xlaugts151
      @xlaugts151  5 років тому

      Mihovil,
      Is the coin bouncing higher each time?

    • @mihovilmikulec
      @mihovilmikulec 5 років тому +1

      @@xlaugts151 That is correct.

  • @JakeLondonRivers
    @JakeLondonRivers 4 роки тому +1

    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?

  • @freddiegbaker
    @freddiegbaker 3 роки тому

    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 :)

  • @jmfs1701
    @jmfs1701 5 років тому

    Where would I put this in my custom script? I just need to put this in my current script about the object destroying part.

  • @PharaO_0
    @PharaO_0 4 роки тому

    and how d you save the coins? for like a shop or something

  • @Malakmuha
    @Malakmuha 5 років тому +1

    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 !...

    • @xlaugts151
      @xlaugts151  5 років тому

      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.

  • @Vishnu-lk7ku
    @Vishnu-lk7ku 3 роки тому +1

    Good video Duude...

  • @user-si8vn9jd3w
    @user-si8vn9jd3w 4 роки тому

    great tutorial thank you so much :))

  • @Mateksk8oz
    @Mateksk8oz 4 роки тому

    Thank you

  • @Max-xj5zx
    @Max-xj5zx 4 роки тому +1

    @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?

  • @hjozefefe
    @hjozefefe 3 роки тому

    Why when I duplicate the counter(TMP), then it not count coins in second one?
    Can somebody help me please?

  • @theplayer2700
    @theplayer2700 2 роки тому

    thanks, its working

  • @raymondsmith8401
    @raymondsmith8401 4 роки тому

    Anyway for me to keep the coins bouncing up and down?

  • @filipe6401
    @filipe6401 4 роки тому

    my Text variable is public but in unity it doesn't appears the drag and drop to set Text value

  • @rhythmandblues_alibi
    @rhythmandblues_alibi 3 роки тому

    Thanks man!

  • @an_games_0437
    @an_games_0437 4 роки тому +1

    thanks man

  • @SageNode
    @SageNode 4 роки тому

    Cannot drag text onto the script slot. just wont let me, not for TMPro or regular text

  • @SplashyandDuckiesadventures
    @SplashyandDuckiesadventures 5 років тому +3

    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 😅

    • @xlaugts151
      @xlaugts151  5 років тому

      Oh, Congratulation my friend.
      Good job and thanks for watching

    • @Mikeul2GT
      @Mikeul2GT 5 років тому

      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

    • @tiefseeee
      @tiefseeee 4 роки тому

      I did the same mistake and didnt get it fixed for a while, so thaks for ur comment u helped me find the error

  • @mikemixsosa4264
    @mikemixsosa4264 4 роки тому +2

    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!

    • @bbugra3
      @bbugra3 3 роки тому

      did u find anything for this? I need the same thing that u wrote :)

    • @mikemixsosa4264
      @mikemixsosa4264 3 роки тому

      No, but use player prefs is way more simple

    • @mitulmahish6145
      @mitulmahish6145 3 роки тому

      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

  • @Magma-uw7yo
    @Magma-uw7yo 5 років тому +2

    hi, how can I find Layer name with game Object ?

    • @xlaugts151
      @xlaugts151  5 років тому

      Hi Magma,
      Do you want to find a layer using code ?

    • @Magma-uw7yo
      @Magma-uw7yo 5 років тому +1

      @@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

    • @xlaugts151
      @xlaugts151  5 років тому

      @@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

  • @progamermaster2685
    @progamermaster2685 3 роки тому

    super video can you help me, when i make a build the text doesnt show

  • @zyckoxd
    @zyckoxd 4 роки тому

    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

  • @MikuNuonuo
    @MikuNuonuo 2 роки тому

    Thank you very much!!!

  • @renatogonzalezparanormal9374
    @renatogonzalezparanormal9374 4 роки тому

    friend to me because when collecting the last coin the image and text are erased from the screen?

  • @eagtf
    @eagtf 4 роки тому

    How can i save the score though??

  • @MajesticQT
    @MajesticQT 4 роки тому +1

    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?

    • @doctordoge5058
      @doctordoge5058 4 роки тому +2

      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.

    • @onurkaya9939
      @onurkaya9939 4 роки тому

      @@doctordoge5058 i can't do this please help me

    • @onurkaya9939
      @onurkaya9939 4 роки тому

      can you help me?

    • @veenu9413
      @veenu9413 3 роки тому

      @@doctordoge5058 Thanks a lot. Had trouble with that. checked the unity forums but couldn't find it there

    • @lec0conut39
      @lec0conut39 2 роки тому

      @@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!

  • @_felix128old2
    @_felix128old2 4 роки тому

    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

  • @Pj-fd8vs
    @Pj-fd8vs Рік тому

    thank you!!!

  • @cursetin9833
    @cursetin9833 3 роки тому

    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?

  • @flareblitz8684
    @flareblitz8684 4 роки тому +1

    what does it mean by "other.gameObject"?

    • @Coconasty
      @Coconasty 4 роки тому

      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

  • @boydhamilton2522
    @boydhamilton2522 4 роки тому

    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);
    }
    }

  • @jovillegas2983
    @jovillegas2983 5 років тому +1

    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?

    • @TheZaru
      @TheZaru 4 роки тому +2

      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 :)

    • @devdev554
      @devdev554 3 роки тому

      Can i get the game file for my assignment😔