I’m currently running through the Unity scripting tutorials and challenging myself to make a game with a win state at the end of each tutorial.
On Tutorial 1, I want the player to “win” when they press ‘R’ ‘G’ and ‘B’ in succession. After they press the correct buttons, key input is disabled and a GUI message appears that says “You win!”
Could someone modify the script to show me how to do this?
This is my current script:
using UnityEngine;
using System.Collections;
public class change_color : MonoBehaviour
{
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown(KeyCode.R))
{
gameObject.renderer.material.color = Color.red;
}
if(Input.GetKeyDown(KeyCode.G))
{
gameObject.renderer.material.color = Color.green;
}
if(Input.GetKeyDown(KeyCode.B))
{
gameObject.renderer.material.color = Color.blue;
}
}
}
I can currently turn the cube either red, green or blue. Attaching a material is not the issue. I am modifying my above post for new rules that might be easier to script.
Also as a future reference, I think it’s best to delete any unused unity functions. So void Start() or Update() or OnGUI() or any other of the like. Not that important, just keeps the script clean and I think saves some frames performance wise.