Hi there,
I’m having an issue with my code. It won’t launch start(); and update() of the class ColorChanger. I have two functions, my menu and ColorChanger (that change the color of a cube to yellow if I press y, red if I press red).
Here is my environement : (see attached file)
Here is my menu :
Menu.cs
####################
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour {
public static bool New = false;
public static bool Load = false;
public ColorChanger roro;
bool showButton = true;
void OnGUI () {
if(showButton)
{
// Make a background box
GUI.Box(new Rect(Screen.width / 4, Screen.height/6, Screen.width /2 , Screen.height/1.5f), “Loader Menu”);
// New
if(GUI.Button(new Rect(Screen.width / 2.7f, Screen.height/4, Screen.width / 4, Screen.height / 10), “New”)) {
New = true;
Load = false;
Application.LoadLevel(1);
//showButton = false;
roro = new ColorChanger();
roro.start();
}
// Load
if(GUI.Button(new Rect(Screen.width / 2.7f, Screen.height/2, Screen.width / 4, Screen.height / 10), “Load Game”)) {
New = false;
Load = true;
Application.LoadLevel(1);
//showButton = false;
}
// Make the second button.
if(GUI.Button(new Rect(Screen.width / 2.7f, Screen.height/1.5f, Screen.width / 4, Screen.height / 10), “Quit Game”))
{
Application.Quit();
}
}
}
}
And here is my ColorChanger :
ColorChanger.cs
###################
using UnityEngine;
using System.Collections;
public class ColorChanger : MonoBehaviour
{
public GameObject cube;
private int CubeColor = 1;
public void start()
{
Debug.Log(“start”);
print(“eokr”);
if (Menu.Load == true)
{
CubeColor = PlayerPrefs.GetInt(“Color”);
StartCoroutine(StartColor());
}
if (Menu.New == true)
{
cube.GetComponent().material.color = Color.blue;
CubeColor = 1;
Debug.Log(“MenuNEw”);
}
}
void update()
{
Debug.Log(“Update”);
if (Input.GetKeyDown (“r”))
{
cube.GetComponent().material.color = Color.red;
CubeColor = 2;
PlayerPrefs.SetInt(“Color”, CubeColor);
}
if (Input.GetKeyDown (“y”))
{
cube.GetComponent().material.color = Color.yellow;
CubeColor = 3;
PlayerPrefs.SetInt(“Color”, CubeColor);
}
}
IEnumerator StartColor()
{
yield return new WaitForSeconds(0.01f);
if (CubeColor == 2)
{
cube.GetComponent ().material.color = Color.red;
}
else if (CubeColor == 3)
{
cube.GetComponent ().material.color = Color.yellow;
}
}
}
The code works, but it won’t turn the cube in another color as it doesn’t even enter in those start/update function (I tried with debug.log and some print everywhere, it wont enter there).
Someone has an idea of what is happening ?