Switch Statement

Hello,
In todays video i will explain how to use Switch statement inside Unity,
I hope You are going to like it.

https://youtu.be/sDwd25g88dA
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SwitchStatementTutorial : MonoBehaviour
{
    //It's a list of possibilities, with an action for each possibility, and an optional default action
    public enum colorToChoose { r,g,b};
    public colorToChoose ChoosenColor;
    //public int i = 0;
    public SpriteRenderer _spriteRenderer;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        SwitchStatementTEST();
    }

    public void SwitchStatementTEST()
    {
        switch (ChoosenColor)
        {
            case colorToChoose.r:
                _spriteRenderer.color = Color.red;
                break;
            case colorToChoose.g:
                _spriteRenderer.color = Color.green;
                break;
            case colorToChoose.b:
                _spriteRenderer.color = Color.blue;
                break;

        }
    }

}


Leave a Reply

Your email address will not be published. Required fields are marked *