- Home /
Textures changing for no reason
Ive got a scene that has some GUI buttons coded along the top of my screen, a Canvas with a Menu Bar along the side (New GUI system) and Planes that are attached to the camera and triggered by the GUI buttons.
The scene uses an ARCamera which augments a cuboid model.
On start up, if the camera isn't pointing at the tracker, it brings up a textured plane telling the user to do so then removes it when it is pointing at the camera.
Here's where the problem starts; when using an Android device, while the camera is pointing away and the plane tells you to point at the tracker, everything is fine. However, when I point it at the tracker, it changes the texture of one of the GUI buttons and the Menu bar to the texture of the cuboid model.
It goes back to the right texture if I press one of the GUI buttons that brings up a Plane attached to the camera.
Testing on an iPad, its fine when not looking at the tracker but when it looks at it, it removes all GUI.
Testing in the Editor, it works absolutely fine.
I've tried a number of things such as changing the cuboid model, changing its texture, changing the coding that goes with it, even reimporting all the assets, but all to no avail.
I don't think it's a coding issue as the textures don't link in anyway. The Menu bar doesn't even reference the GUI buttons or the cuboid model.
Here's the code I'm using for my GUI buttons, I hope someone can help:
using UnityEngine;
using System.Collections;
public class GUI_Buttons : MonoBehaviour {
//The GUI Buttons
public Texture2D HomeButton;
public Texture2D Xray;
public Texture2D App;
public Texture2D Basket;
public Texture2D HelpPage;
public Texture2D Exit;
public Texture2D OFF;
//xray of cuboid model
private GameObject xrayModel;
//normal cuboid model (Texture Sharer)
private GameObject RealTex;
//plane attached to ARCamera
private GameObject APP;
//plane attached to ARCamera
private GameObject HelpWindow;
private bool clicked = false;
void Start(){
xrayModel = GameObject.Find ("ImageTarget/XRAY");
xrayModel.SetActive (true);
RealTex = GameObject.Find ("ImageTarget/bar");
RealTex.SetActive (false);
APP = GameObject.Find ("ARCamera/APP");
APP.SetActive (false);
HelpWindow = GameObject.Find ("ARCamera/HelpWindow");
HelpWindow.SetActive (false);
}
void OnGUI(){
GUI.DrawTexture (new Rect (10, 10, 100, 100), HomeButton);
GUI.DrawTexture (new Rect (120, 10, 100, 100), Xray);
GUI.DrawTexture (new Rect (230, 10, 100, 100), App);
GUI.DrawTexture (new Rect (340, 10, 100, 100), Basket);
GUI.DrawTexture (new Rect (450, 10, 100, 100), HelpPage);
GUI.DrawTexture (new Rect (560, 10, 100, 100), Exit);
GUI.backgroundColor = Color.clear;
if (GUI.Button (new Rect (10, 10, 100, 100), ""))
Application.LoadLevel ("Home");
if (GUI.Button (new Rect (230, 10, 100, 100), ""))
APP.SetActive(true);
if (GUI.Button (new Rect (340, 10, 100, 100), ""))
Application.OpenURL ("http://www.website.com");
if (GUI.Button (new Rect (450, 10, 100, 100), ""))
HelpWindow.SetActive (true);
if (GUI.Button (new Rect (560, 10, 100, 100), ""))
Application.Quit ();
if (GUI.Button (new Rect (120, 10, 100, 100), ""))
clicked = true;
StartCoroutine ("UnSetActive");
StartCoroutine ("TexOn");
if (clicked) {
StartCoroutine ("SetActive");
StartCoroutine ("TexOff");
GUI.DrawTexture (new Rect (120, 120, 100, 100), OFF);
if (GUI.Button (new Rect (120, 120, 100, 100), ""))
clicked = false;
}
}
void SetActive(){
xrayModel.SetActive (true);
}
void UnSetActive(){
xrayModel.SetActive (false);
}
void TexOn(){
RealTex.SetActive (true);
}
void TexOff(){
RealTex.SetActive (false);
}
}