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;
}
}
}
Average Rating