I have a button that is supposed to make a cube dark blue. The texture I’m using is called darkBlue. I get no errors but when I click the dark blue button my cube doesn’t change colors. Any help would be nice.
using UnityEngine;
using System.Collections;
public class Color : MonoBehaviour
{
public Color instance;
public string CurrentMenu;
public GUIStyle MenuLabelGUIStyle;
public GUIStyle colorBlue;
public GUIStyle colorBlueL;
public GUIStyle colorGreen;
public GUIStyle colorGreenL;
public GUIStyle colorPink;
public GUIStyle colorRed;
public GUIStyle colorYellow;
public GUIStyle colorPurple;
public GUIStyle colorOrange;
public GUIStyle colorBrown;
public bool isChosen = false;
public float timescale = 1.0f;
private Texture2D darkBlue;
// Use this for initialization
void Start ()
{
instance = this;
CurrentMenu = "choColor";
darkBlue = (Texture2D)Resources.Load("darkBlue.jpg");
}
void OnGUI()
{
if (CurrentMenu == "choColor")
Menu_choColor();
}
// Update is called once per frame
public void NavigateTo(string nextmenu)
{
CurrentMenu = nextmenu;
}
private void Menu_choColor()
{
if (isChosen == false)
{
GUI.Box(new Rect(10, 10, 200, 50), "Choose Your Cube Color", MenuLabelGUIStyle);
GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "");
Time.timeScale = 0.0f;
if (GUI.Button(new Rect(10, 130, 50, 50), "", colorBlue))
{
isChosen = true;
Time.timeScale = 1.0f;
gameObject.renderer.material.mainTexture = darkBlue;
}
if (GUI.Button(new Rect(70, 130, 50, 50), "", colorBlueL))
{
isChosen = true;
Time.timeScale = 1.0f;
}
if (GUI.Button(new Rect(130, 130, 50, 50), "", colorGreen))
{
isChosen = true;
Time.timeScale = 1.0f;
}
if (GUI.Button(new Rect(190, 130, 50, 50), "", colorGreenL))
{
isChosen = true;
Time.timeScale = 1.0f;
}
if (GUI.Button(new Rect(250, 130, 50, 50), "", colorPink))
{
isChosen = true;
Time.timeScale = 1.0f;
}
if (GUI.Button(new Rect(10, 200, 50, 50), "", colorPurple))
{
isChosen = true;
Time.timeScale = 1.0f;
}
if (GUI.Button(new Rect(70, 200, 50, 50), "", colorRed))
{
isChosen = true;
Time.timeScale = 1.0f;
}
if (GUI.Button(new Rect(130, 200, 50, 50), "", colorYellow))
{
isChosen = true;
Time.timeScale = 1.0f;
}
if (GUI.Button(new Rect(190, 200, 50, 50), "", colorOrange))
{
isChosen = true;
Time.timeScale = 1.0f;
}
if (GUI.Button(new Rect(250, 200, 50, 50), "", colorBrown))
{
isChosen = true;
Time.timeScale = 1.0f;
}
}
}
}