Menu Close

Dropdown in Unity | Change Image Color Using Dropdown | Unity Tutorial 16

0 0
Read Time:35 Second

👉 Description:

You’ll learn About the Dropdown. You’ll Also Learn How to change image color using a dropdown.

C# Script For Dropdown:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DropdownTut : MonoBehaviour
{
    [SerializeField] Dropdown dropdown;
    [SerializeField] Image image;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if(dropdown.value==0)
        {
            image.color = Color.red;
        }
        else if(dropdown.value==1)
        {
            image.color = Color.blue;
        }
        else if(dropdown.value==2)
        {
            image.color = Color.green;
        }
        else if(dropdown.value==3)
        {
            image.color = Color.yellow;
        }
        else if(dropdown.value==4)
        {
            image.color = Color.gray;
        }
        else
        {
            image.color = Color.black;
        }
    }
}
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

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

%d bloggers like this: