Unity Beginner Scripting Tutorial Part 4: Conditionals

Поділитися
Вставка
  • Опубліковано 28 чер 2024
  • The Unity Beginner Scripting Tutorial series is a simple series just meant to get you to understand the compiler. If you're having trouble with syntax and words like syntax, then this series is meant to get you up and running.
    In this video we will be talking about function in context of Unity and C#.
    Buy me a coffee: Ko-fi.com/alvinroe
    I hope you are as excited as me. Please like, subscribe, and leave a comment

КОМЕНТАРІ • 11

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

    I was almost screaming at the screen and asking myself if I was stupid until I took up your suggestion at the end and tried my version of the code and it worked. I did not use a second boolean, I just used theEnd boolean in my code. I don't know if it is the right way to go but I am content at least I have done it. Your tutorials have been very clean, self-explanatory until now. This one made me almost quit but I think I got it and I believe solving this situation in my own way as you suggested gave me the will to go on about this and learn sufficient coding to create a simple game of my own. I don't know about the future of this channel and this series particularly but thank you for the awesome infos!

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

    This is a great tutorial, thank you so much. This episode is where I started getting a little bit confused. After the tutorial, I tried writing my own script with if statements, as suggested. It was hard to do so, but I was able to get it to click in my head and get it done. I only used one boolean in my script to get the last Debug.Log inside of Update to print only once. Here is my script for anyone who is interested:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class IfStatement : MonoBehaviour
    {
    int playerHealth = 20;
    int demonHealth = 10;
    int demonAttack = 2;
    int playerAttack = 2;
    bool ending = false;
    [SerializeField] string inputField = "Type your inputs here";
    void Start()
    {
    Debug.Log("A demon has appeared, Player is in danger!");
    }
    void Update()
    {
    if (demonHealth != 0)
    {
    if (inputField == "Attack")
    {
    Debug.Log("Player attacks Demon for " + playerAttack + " !");
    demonHealth = demonHealth - playerAttack;
    Debug.Log("The Demon has " + demonHealth + " remaining!");
    Debug.Log("The Demon strikes back for " + demonAttack + " !");
    playerHealth = playerHealth - demonAttack;
    Debug.Log("The Player has " + playerHealth + " remaining!");
    inputField = "Type your inputs here!";
    }
    }
    if (ending == false && demonHealth == 0)
    {
    Debug.Log("The demon has been eliminated!");
    Debug.Log("The player is victorius!");
    ending = true;
    }
    }
    }

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

    Man, your videos is amazing. Thanks for living and making this tutorials

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

    Awesome tutorial as always!

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

    Love your Unity tutorials, glad to see you're covering Unity again!

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

    1 thing. at the end of this series can you please do a troubleshooting/fixing common c# errors.

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

    This one was where it started to get a bit confusing. I couldn't get the game to run after all of the erasing and re-writing around the 20:00 mark. It took me a while to figure out that I had deleted a } somehow and that was throwing the whole thing off. I went over it back and forth so many times... but despite that hangup, I look forward to more of these. The challenges are fun!

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

      Easily done, I've done it myself at least once before. LOL

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

    Great lesson man, i spent a ton of time with the challenge this time around, listening and watching you complete the task after i already completed it was definitely eye opening, seeing how i could of done things differently and more efficiently. I learned a lot that I’ll take into my future projects!

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

    I'm seeing a problem with this script. At the end there 25:18 you see enemy hp goes to 0 first. Then it attacks the player one more time before it says victory for the player even tho we had if enemyhealth == 0. What happened?

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

    i watch this video over n over i really didnt get it maybe i need to watch over n over again
    i lost at
    Void start
    testbool = playerAction == "Attack";
    if(testBool)
    {
    Debug.Log("Then this happen");
    }
    after that the rest of the video still didnt get anything im so lost at it