How To Make A 2D Cookie Clicker Game In Unity - Tutorial 04 - If Statements - Best Guide - androidgamestore.net

How To Make A 2D Cookie Clicker Game In Unity – Tutorial 04 – If Statements – Best Guide

Jimmy Vegas
Views: 41268
Like: 518
In this tutorial we write some logic code in the form of IF statements to help us create a Status Box.
✦ Subscribe:
✦ Patreon:
✦ FREE Assets:
✦ Facebook:
✦ Twitter:

———————————–

✦ Start your game development career today and learn how to make a game through the power of Unity. Every Unity Tutorial at JV Unity costs NOTHING from you, and any support received through YouTube, Patreon or Facebook is greatly appreciated.

———————————–

SPECIAL THANKS TO OUR LATEST PATRONS PIERRE, CHRISTIAN NEAT & TOM KOLLMER @
—————–
Who Is Jimmy Vegas?
—————–
Jimmy Vegas is one of the top YouTube tutorial developers. In depth Unity Tutorials teaching you how to make a game in unity 3d! My unity tutorials include development, programming in C#, coding logic and more. For beginners, it’s easy how to learn unity with tips and tricks you can make a game for FREE. I provide FREE assets for you to use and learn.

Start your game development career today, for free. #UnityTutorial

24 Comments

  1. I know this is a bit late, but if you are having problems with the StatusBox, the problem may be the following: The variable in our script 'SellCookies.cs' is called statusBox, it should be called statusText, since what we need to attach to that is the TEXT not the BOX that contains the text. It just confuses beginners, and more likely any reader unfamiliar with the game.Remember to attach to THAT field in Unity the TEXT, not the BOX. You can rename it or not, it doesn't change much.

  2. Dude, I no joke subscribed to you yesterday and boom, another clicker game tutorial

  3. Just a small side note: In your script is it possible to use a try…catch block? Something along the lines of this:

    public void ClickThebutton(){
    ….try{
    ……..if (GlobalCookies.cookieCount == 0)
    …………throw new NotEnoughCookiesException;

    ……..GlobalCookies.cookieCount -= 1;
    ……..GlobalCookies.cashcount += 1;

    ….}catch(NotEnoughCookiesException e){
    ……..statusBox.GetComponent<Text>().text = 'Not enough Cookies to sell!';
    ….}catch(Exception e){ # Less specific, every other exception other than the one above will fall in here
    ……..#Do something
    ….}
    }

    To my knowledge, it's good practice to put almost everything in a try…catch block so you have more control over the possible exceptions that may occur.

  4. Thanks for the guides. I really want to know how to create that "Cookie Maker"

  5. Hi, great tutorials, the only problem I have is I can't get the text to fade in game, fades in scene mode when playing the animation but not when playing game, I have followed through a couple of times and tested a few things (can't animate text color at all but text movement animates fine) is there anything in unity I might need to change? everything I have done is exactly the same as yours.

  6. I dont get it
    The Animation wont stop playing after I pressed the sell button

  7. Its possible to make this animation "spawner/showed" everytime i click the button? I mean, how can i spam it. I want to use it on the cookie. SOo when i click cookie it says "+1" or "+256" .. etc ..

  8. why we need to make animation as legacy?

  9. UnassignedReferenceException: The variable statusBox of SellCookie has not been assigned.

    What do I do???

  10. Can someone please help me, when i've come to the end of this video it gives me an error, as soon as i sell cookies when i got 0$, i cant still sell them but the error is pretty annoying, it says " 'StatusText' AnimationEvent has no function name specified!"
    Can someone help me?

  11. Is it me or it would be better to do things like the code below, then you can't assign a another GameObject than a Text and Text properties are rightly available. Or this in the long run can block some flexibility? Thx

    public UnityEngine.UI.Text statusText;

    public void Button_Click()
    {

    statusText.text = "Not enough cookie to sell!";
    statusText.GetComponent<Animation>().Play("StatusTextDisapear");


    }

  12. @Jimmy Vegas how can I make it so that I can spam the sell cookie button and the animation will restart every time I click it? Thanks!

  13. It shows the status box where i drag the script on mainbuttonclick and not sell cookie script

  14. Another great tutorial … was able to follow it with a couple of rewinds when things went a bit quick for me. But I plan to do the whole process from beginning to end a couple of times soon so that I can be sure I have understood it before I move on.

  15. I keep getting this:

    UnassignedReferenceException: The variable statusBox of Sell has not been assigned.
    You probably need to assign the statusBox variable of the Sell script in the inspector.
    UnityEngine.GameObject.GetComponent[T] () (at C:/buildslave/unity/build/Runtime/Export/GameObject.bindings.cs:28)
    Sell.sell () (at Assets/Scripts/Sell.cs:15)
    UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166)
    UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
    UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:66)
    UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:108)
    UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
    UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
    UnityEngine.EventSystems.EventSystem:Update()

  16. I have problem with script in 10:58
    Error : Assets/Scripts/SellCookie.cs(15,36): error CS0246: The Type or namespace name 'text' could not be found (are you missing a using directive or an assembly reference?)
    What should I do? HELP!

  17. If you are typing statement such as if or *else*… you can just press double TAB and that's it! Don't thank me xd

  18. AssetsScriptsSellCookie.cs(16,23): error CS0119: 'GameObject.GetComponent<T>()' is a method, which is not valid in the given context

    help

Leave a Reply

Your email address will not be published.