- Home /
Select-color menu that loops through colors as button is pressed
Hi, I am currently trying to make a menu that loops through the colors available for the main character with the use of 2 arrow keys. Does anyone know how I can do this efficiently? [1]: /storage/temp/172562-shop.jpg
Answer by Pokedlg3 · Dec 15, 2020 at 03:51 AM
I don't understand what you want to do? could you be more specific?
do you want to change color when he clicks a key?
Yes, when the button is pressed it should go to the next color. I currently have a menu where you click on a colored button and the rocket material then becomes that color but I would like to do it with these arrows instead if possible.
Put this script on your rocket:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColorTest : $$anonymous$$onoBehaviour
{
[SerializeField]private Color blue;
[SerializeField]private Color green;
[SerializeField]private Color red;
[SerializeField]private Color yellow;
[SerializeField]private Color gray;
[SerializeField]private Color black;
[SerializeField]int lastColor = 0;
[SerializeField]private $$anonymous$$aterial mat;
void Start()
{
green = Color.green;
red = Color.red;
yellow = Color.yellow;
blue = Color.blue;
black = Color.black;
gray = Color.gray;
mat = gameObject.GetComponent<$$anonymous$$eshRenderer>().material;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.RightArrow))
{
lastColor++;
}
if(Input.GetKeyDown(KeyCode.LeftArrow))
{
lastColor--;
}
if(lastColor == 0)
{
mat.color = blue;
}
if(lastColor == 1)
{
mat.color = red;
}
if(lastColor == 2)
{
mat.color = yellow;
}
if(lastColor == 3)
{
mat.color = green;
}
if(lastColor == 4)
{
mat.color = black;
}
if(lastColor == 5)
{
mat.color = gray;
}
if(lastColor < 0)
{
lastColor = 5;
}
if(lastColor > 5)
{
lastColor = 0;
}
}
}
Your answer
Follow this Question
Related Questions
Aligning animation with movement. 0 Answers
Slime script? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Simple 2D Enemy AI 3 Answers
Integration tests fail on 'Run All' 2 Answers