Beginning C# with Unity (2023 Edition) - Operators

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ต.ค. 2024
  • Once you've defined your variables, you need to operate on those variables. to change the values. Thankfully, C# comes with lots of different operators. In this episode, you'll get a walkthrough of the more commonly used operators.
    This episode is sponsored by www.kodeco.com.
    Note: Unity is required. You can download the free version from Unity3d.com. This course has been developed using just the personal version.
    Kodeco aims to be the best online learning platform for mobile developers at every step of their career, all the way from building your first app, to becoming a respected expert in your field.
    Previously known as raywenderlich.com, our products have made a difference in the lives of thousands of developers across the world, helping them to get their first job as a mobile developer, grow their careers as part of a dev team, or create the app of their dreams.
    About Unity (from Wikipedia):
    Unity is a cross-platform game engine developed by Unity Technologies and used to develop video games for PC, consoles, mobile devices and websites. First announced only for Mac OS, at Apple’s Worldwide Developers Conference in 2005, it has since been extended to target more than fifteen platforms.
    It is now the default software development kit (SDK) for the Wii U.]Unity Pro is available for a fee and Unity Personal has no fee; it is available for any use to individuals or companies with less than US$100,000 of annual gross revenue.
    On March 3, 2015 with the release of Unity 5.0, Unity Technologies made the complete engine available for free including all features, less source code and support.
    Unity is noted for an ability to target games to multiple platforms.Five versions of Unity have been released. In 2006 at the 2006 WWDC trade show, Apple, Inc. named Unity as the runner-up for its Best Use of Mac OS X Graphics category.
    About C#:
    C# (pronounced as see sharp) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines.
    It was developed by Microsoft within its .NET initiative and later approved as a standard by Ecma (ECMA-334) and ISO (ISO/IEC 23270:2006). C# is one of the programming languages designed for the Common Language Infrastructure.
    C# is intended to be a simple, modern, general-purpose, object-oriented programming language. Its development team is led by Anders Hejlsberg. The most recent version is C# 5.0, which was released on August 15, 2012.

ความคิดเห็น • 113

  • @eyggamer6484
    @eyggamer6484 10 หลายเดือนก่อน +26

    This is to hard for me , because i am just 11 years old.but when i saw your videos i knew i had the chance to make my dream come true.thank you for the help vegetarian zombie 💪💪💪💪💪👈

    • @MiloGameDev
      @MiloGameDev 9 หลายเดือนก่อน +3

      Well, stay focused. Making money that young? Shoot, millionaire by 11 is crazy.

    • @pasipaaryna2119
      @pasipaaryna2119 8 หลายเดือนก่อน +2

      Keep working and you will understand and improve, you are very smart for 11 year old💪

    • @hylea96
      @hylea96 6 หลายเดือนก่อน +4

      Some concepts are hard even for adults to grasp so just take it slow, you'll get there. Learning to code is a very useful way to spend your time, so just keep at it!

    • @DARK_AMBIGUOUS
      @DARK_AMBIGUOUS 2 หลายเดือนก่อน +1

      I remember trying to make games on our families computer when I was like 9, I used something called game maker 8 and this other thing called Reality Factory, I remember spending hours reading the tutorial thing and I got stuck so many times. Now I am 23 and I completely know how to use Unity and Visual Scripting but I've hit the impenetrable barriers of Visual Scripting such as the horrible performance and random pieces of code just not running for absolutely no reason and replaying the scene sometimes fixes it, like sometimes update will excicute but for no reason, fixed update will not. I gave up on visual scripting because games made with it can barely even run on mobile, I've finally decided to go all in on C#. I've been a game developer for about 4 years and I'm finally switching over to C#.

    • @SpaghettiDev11
      @SpaghettiDev11 หลายเดือนก่อน

      same i already know a code language called lua and its similar to this so u should whach lua code tutorial and then come back to this k

  • @ayayron8221
    @ayayron8221 ปีที่แล้ว +20

    Getting frustrated with Playmaker because the devs on TH-cam don’t ever respond to any queries so I decided to just go old school. I’m super glad you’re doing an updated Unity tutorial! Hope to see this series to completion, keep up the good work!

  • @oldie-se
    @oldie-se ปีที่แล้ว +6

    I'm forcing myself hard on C# because I need that pressure. And my head always wants to understand why the things are like they are. Until now you solved many many questions I had when I started the Unity Junior Programmer Lesson.

    • @VegetarianZombie
      @VegetarianZombie  ปีที่แล้ว +4

      If you are forcing yourself to learn C#, question yourself about where the resistance is coming from. It also helps to focus on what you want to do with the language. Aim to have fun with it. Be playful with it. :D

  • @ugatorf
    @ugatorf ปีที่แล้ว +32

    Hey guys so I could not for the life of me get this to work when I tried starting a new script from scratch for the exercise. For me I had to go back and review the operators code and discovered that at the end of the new script I needed to add textMeshPro.text = $"{totalAmount}";. or just textMeshPro.text = $"{whateveryounamedyourvariablehere}"; Which wasn't mentioned in the fast-forwarded example of how to get the challenge assignment to work correctly.
    I hope that helps any one else that was having that issue!

    • @MaxW0lf
      @MaxW0lf ปีที่แล้ว +3

      Thank u kind soul! I almost died trying to figure why it didn't show the changes, i see that you got to pay attetion to details like this in future projects. Thanks again!

    • @doninfinte8063
      @doninfinte8063 ปีที่แล้ว

      Saved me so much stress bro, thank you!

    • @oo0o0
      @oo0o0 ปีที่แล้ว +2

      Aye, this step is missing from the video.

    • @Googly-Cricket-j
      @Googly-Cricket-j 9 หลายเดือนก่อน +1

      Thank you so much, my heart dropped when the code didn't work.

    • @RaXx1100
      @RaXx1100 8 หลายเดือนก่อน

      Thank you so much. I wondered why it didnt work. My own worked fine (i did it very different than him). than i wanted to do his and it didnt worked. Thank you so much :)

  • @KontrollerMonkey
    @KontrollerMonkey ปีที่แล้ว +3

    Thanks for the extra explanations most tutorials just assume you know a bunch of stuff already

  • @akrimahuzaifa4566
    @akrimahuzaifa4566 ปีที่แล้ว +26

    If you aren'y getting result of end video task is just because he didn't show
    textMeshPro.text = $"{totalAmount}";
    in the last of the code
    Thanks me later

    • @Obliterator786
      @Obliterator786 ปีที่แล้ว

      Thank you do much i was genuinely confused i wasn't showing result thanks 😊

    • @huntersole68
      @huntersole68 11 หลายเดือนก่อน

      this should be pinned

    • @l3monpldge534
      @l3monpldge534 9 หลายเดือนก่อน

      after 45 minutes of beating my head against a wall I saw this, ty sir

    • @dezzmay
      @dezzmay 7 หลายเดือนก่อน +1

      Dude i thought i messed something up and was about to abandon this after redoing it like 10 time thank you!

    • @GeryNH
      @GeryNH 6 หลายเดือนก่อน

      Thank you so much!

  • @Justin-cx8lv
    @Justin-cx8lv ปีที่แล้ว +4

    Thank you for another great video!

    • @VegetarianZombie
      @VegetarianZombie  ปีที่แล้ว +4

      Thank you Justin! I always appreciate your kind messages :)

  • @koni.K
    @koni.K 9 หลายเดือนก่อน

    the casting part got me confused but in the end i figured it out thanks for making these tutorials it really helps

  • @felipeleon8614
    @felipeleon8614 ปีที่แล้ว +2

    i accidentally created a program that calculates the percentages of a float, i'm happy that it works😁

  • @CekTopGaZa1988
    @CekTopGaZa1988 ปีที่แล้ว +2

    Thank you for your lessons!!!

  • @dabunnisher29
    @dabunnisher29 ปีที่แล้ว +1

    Nice use of one of my favorite bands : joyDivision

  • @chubichubaka187
    @chubichubaka187 ปีที่แล้ว

    Love your teaching method 😂😂😂 11:00. But seriously, nice job!!!

  • @CreeperKiller420
    @CreeperKiller420 11 หลายเดือนก่อน

    I didn't expect to learn Karate here. Thank you, now I can defend myself.

  • @AzulinTeniente
    @AzulinTeniente 7 หลายเดือนก่อน +1

    Real programmer moment... ( 11:00 )
    «If you are confused - welcome to the club!»

  • @S0meT3n
    @S0meT3n ปีที่แล้ว +3

    Hey man, been loving ur course so far. Just wanted to know a scenario where postfix will be useful.

    • @VegetarianZombie
      @VegetarianZombie  ปีที่แล้ว +2

      Personally I avoid all prefix and postfix operators. That said, they can be really useful when you need to assign a value while using that value as a loop iterator (we haven't covered loops yet)
      while (i < 5) {
      int someVariable = i++;
      }
      You've both assigned a value to someVariable (which your are presumably going to use somewhere while you also incremented the loop at the same time.

  • @Ahmedkahlaa
    @Ahmedkahlaa 10 หลายเดือนก่อน

    Thank u for this great video

  • @thetunesplace
    @thetunesplace ปีที่แล้ว +1

    can't wait for the next episode

    • @VegetarianZombie
      @VegetarianZombie  ปีที่แล้ว +2

      Sorry for the delay - it’s coming. Life got in the way 🙂

  • @iWannaBeBetterForGod
    @iWannaBeBetterForGod ปีที่แล้ว +2

    Super useful! When will we learn about input commands and stuff like that (like movement) or maybe game logic? Looking forward to the next vid!

    • @VegetarianZombie
      @VegetarianZombie  ปีที่แล้ว +5

      Not for awhile - movement and game logic uses the Unity API, but before you can adequately use it, you need to know C# first. That said, if you are eager to get started, check out the Code Monkey YT channel.

    • @iWannaBeBetterForGod
      @iWannaBeBetterForGod ปีที่แล้ว +1

      @@VegetarianZombie alrighty, thank you for the help, I'll check it out! I want to try to make a game while I learn, its gonna be a 2D fast paced game, hopefully I learn something along the way, programming is hard lol

  • @Saxopwned23
    @Saxopwned23 ปีที่แล้ว +2

    Hey there, for some reason I cannot get the function to show up when my script is connected to the button. Only "No Function" exists as an option in the drop down, even when I did everything exactly the same as your example. Any ideas?
    Edit: nevermind, it's because I was trying to add the script to the OnClick() event, duh!

  • @BORDEV
    @BORDEV ปีที่แล้ว +3

    personally i turned the amount into a float divided into 100 and then multiply it by the percentage so that you can just write 20 for 20 percent i dont know if it ineffiecent or is there anything wrong with doing it like that since it works!

  • @BRINDANI2000
    @BRINDANI2000 3 หลายเดือนก่อน

    Didn't you mention using a decimal whenever money was involved? Separately, I'm not sure why but the public variables I defined didn't show up in Unity. Oh well, another opportunity for troubleshooting.

  • @CosplayZine
    @CosplayZine 8 วันที่ผ่านมา

    For anyone doing this tutorial, I couldn't get the MyOpperators dropdown menu to show up to click on DisplayMessage Function until I added the script to both the game object and the text gameobjects. Having it only on the button object doesn't seem to work by it's self. I am not sure if I miss understood that or if it was an oversight in this tutorial (or if unity changed how this works)

  • @EnjoyPoPcornYagnik
    @EnjoyPoPcornYagnik 6 หลายเดือนก่อน

    What is the song genre called which was played while explaining the challenge of the tip 18:30 calculator?

  • @YOUNERD6
    @YOUNERD6 7 หลายเดือนก่อน +1

    I know this comment is a bit late in reply but I can't find the DisplayMessage in operators on 6:52, anyone know what this problem could be cause I can't find the answer.
    Asides this issue thank you so much for these lessons, I've already learned more than what I got from wasting cash in college.

    • @dihydrogenoxide4775
      @dihydrogenoxide4775 5 หลายเดือนก่อน +2

      I had the same issue, I forgot to capitalize the D in DisplayMessage. Recheck your code and make sure you wrote it properly. Sorry for the late reply

    • @YOUNERD6
      @YOUNERD6 5 หลายเดือนก่อน

      @@dihydrogenoxide4775 found the problem, was exactly as you said lol, thank you tho

  • @CreeperKiller420
    @CreeperKiller420 11 หลายเดือนก่อน +1

    strength is such a weird looking word

  • @Ghost-Toast819
    @Ghost-Toast819 10 หลายเดือนก่อน

    was not getting display message under operators. couldnt figure it out but it was because i didnt save the operators script into unity. when in doubt make sure you have saved your code

  • @jordanfanning5625
    @jordanfanning5625 ปีที่แล้ว +4

    Loving the series so far. I'm running into a bit of an error where when I click the button, the "120" is not updating and "This space for rent" remains. I've gone back to look a few times and can't seem to find my error. Any ideas?

    • @VegetarianZombie
      @VegetarianZombie  ปีที่แล้ว +3

      Offhand, no idea. My guess it’s either with your code (feel free to paste it here) or you didn’t correctly set it up on the OnClick event in the Unity editor. If your code looks good, then check out the button and make sure your new script was added to Text game object. Yes, there are many possible points of failure here 😀

    • @thedrewster2437
      @thedrewster2437 ปีที่แล้ว

      @@VegetarianZombie Im having this exact same problem and im not sure whats going on.

    • @thedrewster2437
      @thedrewster2437 ปีที่แล้ว

      @@VegetarianZombie Ok i just added "textMeshPro.text = $"{totalAmount}";" at the end and now its working.

    • @kekeslider
      @kekeslider ปีที่แล้ว

      ​@@VegetarianZombie ​ I also had the same problem!! As I was about to send this comment, I solved it...
      We need to add the following to the end of the script, inside the two } closing curly brackets, below the "int totalAmount = (int)tipAmount + amount;" part:
      textMeshPro.text = $"{totalAmount}";
      Adding this will reference the totalAmount we made and let TMP print it.
      ______________________________________________________________
      The completed code should read like this if you want it to work:
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using TMPro;
      public class TipCalculator : MonoBehaviour
      {
      public int amount = 0;
      public float percentage = 0.2F;
      private TextMeshProUGUI textMeshPro;
      // Start is called before the first frame update
      void Start()
      {
      textMeshPro = GetComponent();
      }
      // Update is called once per frame
      void Update()
      {
      }
      public void CalculateTip()
      {
      float tipAmount = (float)amount * percentage;
      int totalAmount = (int)tipAmount + amount;
      textMeshPro.text = $"{totalAmount}";
      }
      }
      Yes, we do get the tools to figure this out from the tutorial, but... this was not included in the provided answer key. Hopefully this saves others from wasting a lot of time on this like we did..!
      I'm loving your tutorial series, and still very appreciative of your hard work to create them, but please check that your answer keys really do show us how to complete the script! Moving on to the next lesson now :)

    • @captainnelson9833
      @captainnelson9833 ปีที่แล้ว +13

      Hello. If you didn't figure it out, I'm here. I'm guessing you made a new script just like the video did.
      You most likely did everything right. Used TMPro, set your public variables, did the tipAmount math at the end, and attached it to the button correctly.
      In the video, the host forgot to say you need to remember to add textMeshPro.text = $"{totalAmount}"
      Or the button won't write anything (the script added the variable and the button was waiting for what to write, you just forgot to tell it to write anything).

  • @davidempson215
    @davidempson215 8 หลายเดือนก่อน

    just saying, if once u build the tip calculator as shown in the video, at least for me, it wouldn´t display the number where the text, after like 30mns trying to figure it out, i managed to realize that the value of totalAmount wasn´t paired to the text, to fix it i synchronized the textMeshPro to the int totalAmount
    Sintaxis: textMeshPro.text = $"{totalAmount}";

  • @alexass-i7f
    @alexass-i7f 9 หลายเดือนก่อน +2

    mine did not write anyhting when i attached the tip calculator thingy and i checked 5 times now too see if you have done anything different, but it does not write 120 after i put in 100, im confused

    • @alexass-i7f
      @alexass-i7f 9 หลายเดือนก่อน

      like i pressed the button but it still just says this space is for rent
      >(

    • @DartzTheGamer
      @DartzTheGamer 9 หลายเดือนก่อน +2

      I am having the same issue and I have no idea what's causing it. I've triple checked the code and even redid everything from scratch and still does nothing.

    • @wilmerronnemyr8720
      @wilmerronnemyr8720 9 หลายเดือนก่อน

      did you add textMeshPro.text = $"{totalAmount}";?

  • @nightmare-zk5fw
    @nightmare-zk5fw ปีที่แล้ว +1

    You are underrated tbh

  • @RannimGraphics
    @RannimGraphics 6 หลายเดือนก่อน

    but i feel like an end of these or when learn most will forgot a lot or no idea what im doing still, just waited of loads of part idk im gonna get confused for sure

  • @redresultyt
    @redresultyt 9 หลายเดือนก่อน

    I did the exact same task as you did, I even deleted everything and tried again and again, the button doesn't do anything on click, any reasons as to why maybe?

  • @Gaming113-YT
    @Gaming113-YT 10 หลายเดือนก่อน

    Why is amount * percentage = the amount is a float is it because were making this example 100 into a float by doing that and now its 100F or what

  • @alucard6992
    @alucard6992 9 หลายเดือนก่อน +1

    Am i the only one who thinks that the song choice was so weird for a c sharp tutorial 😂

  • @PrehzK
    @PrehzK 9 หลายเดือนก่อน

    By the "On Click" section I do not have 'DisplayMessage" option, I have the other options though. Am I doing something wrong? :(

    • @PrehzK
      @PrehzK 9 หลายเดือนก่อน

      I found the problem! I wrote bad code in the "MyOperators" file :)

    • @Climbingandtech
      @Climbingandtech 8 หลายเดือนก่อน

      @@PrehzK i am having the same problem how did you fix it?

    • @PrehzK
      @PrehzK 7 หลายเดือนก่อน +1

      @@Climbingandtech I know it's late but for anyone who wants to know, the code I put in originally was wrong even tho I didn't get an error. I fixed it by just retyping my "bad code"

    • @Climbingandtech
      @Climbingandtech 7 หลายเดือนก่อน

      @@PrehzK thanks

  • @Gaming113-YT
    @Gaming113-YT 10 หลายเดือนก่อน

    i cant i dont understand anythinghow did it work for you with you you setting the text to the amount?

  • @Danachew
    @Danachew ปีที่แล้ว

    Did I slide? Am I the only one who remembers it as PEMDAS?

  • @CalebCimeus-qd5kp
    @CalebCimeus-qd5kp 6 หลายเดือนก่อน

    so am I the only one who thought 3-18+2 = -17? according to PEMDAS wouldn't the addition of 18+2 happen first? why is 3-18 happening first to give the result -13?

    • @fkingbeast77
      @fkingbeast77 6 หลายเดือนก่อน +1

      Multiplication/ Division are grouped started left to right. Same with addition/subtraction.
      PEMDAS looks more like (P)(E)(MD)(AS)

  • @Triforceman2007
    @Triforceman2007 5 หลายเดือนก่อน

    I need help when i open my options on the button DisplayMessage dosnt show up

    • @dihydrogenoxide4775
      @dihydrogenoxide4775 5 หลายเดือนก่อน +1

      I had the same issue, I forgot to capitalize the D in DisplayMessage. Recheck your code and make sure you wrote it properly. Sorry for the late reply

  • @GamerBoy_India
    @GamerBoy_India ปีที่แล้ว

    hey bro i have a doubt in my code i want to freeze my gameobjects position in y direction by script and as much i know i had written correct code but it is not running can u help me with what i have done wrong
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class groundCheckCollider : MonoBehaviour
    {
    public Rigidbody2D rb;


    void Update()
    {

    }
    private void onTriggerExit2D(Collider2D col)
    {
    if (col.tag == "GroundTiles")
    {
    rb.constraints = RigidbodyConstraints2D.FreezePositionY;
    }
    }

    • @VegetarianZombie
      @VegetarianZombie  ปีที่แล้ว +1

      You should ask this question on the Unity forums or stack overflow.

  • @ftdbaba3642
    @ftdbaba3642 ปีที่แล้ว

    Hey I'm sorry to say my tip calculator can't work I don't know why can you please help me?

  • @ahmedibrahem-q2r
    @ahmedibrahem-q2r ปีที่แล้ว

    17:07

  • @itskristis
    @itskristis 4 หลายเดือนก่อน +1

    I didnt understand the challange so I made a percent calcalator ex: i give 20$ and the tip is 5% so I have to tip 1$ aperantly I misunderstood the challange 🤣

  • @tikos8063
    @tikos8063 6 หลายเดือนก่อน

    im loosing my mind with this dam calculator. I triple checked the code..but yet its not working despite being identical.

  • @idiotic5436
    @idiotic5436 หลายเดือนก่อน

    Bro i can make calculator in unity now 💀

  • @huntersole68
    @huntersole68 11 หลายเดือนก่อน +1

    i am not smart enough for this i give up

    • @VegetarianZombie
      @VegetarianZombie  11 หลายเดือนก่อน +7

      That isn't true. You are incredibly smart. You can communicate through written language which is far more complex than C#.
      Chances are, my teaching is not approaching the material that is accessible to you. I suggest looking at other tutorials from different instructors to see the material from a different perspective. And FYI - part learning process is going through that "valley of despair". The amazing thing is when it all clicks and you feel like Neo from the Matrix. It just takes time and patience with yourself.
      Good luck!

  • @griff424
    @griff424 ปีที่แล้ว

    am i in a math class

  • @fridmmmdli1527
    @fridmmmdli1527 4 หลายเดือนก่อน

    Vegetarian Zombie 💀💀💀💀💀💀💀💀💀💀💀💀💀💀

  • @meta-beaver
    @meta-beaver ปีที่แล้ว

    That dog at least doing something... I can't even apprehend what the author of the video talking about... All this stuff like white noise for me, I listen but understand nothing.

    • @VegetarianZombie
      @VegetarianZombie  ปีที่แล้ว +3

      If you can't apprehend the subject matter of this episode, you may be "diving too deep, too fast". Your best bet is to rewatch the earlier videos again as well as other C# videos to provide a firmer foundation. Trust me, it only gets harder from here.

    • @meta-beaver
      @meta-beaver ปีที่แล้ว +1

      @@VegetarianZombie Thanks, I will try.

  • @noobgamerrd8366
    @noobgamerrd8366 หลายเดือนก่อน

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using TMPro;
    public class MyOperator : MonoBehaviour
    {
    private TextMeshProUGUI textMeshPro;
    // Start is called before the first frame update
    void Start()
    {
    textMeshPro = GetComponent();
    }
    // Update is called once per frame
    void Update()
    {

    }
    public void DisplayMessage()
    {
    textMeshPro.text = "Button Clicked!";
    }
    }
    i am getting a null reference exception when i click the button where did i get wrong?