- Home /
GUItext works 1 of 3 situations?
Scenario: Objects collide, player object changes color of collided object(works), other objects is set to inactive(works), sound is played(works), text on screen says name of color(or the material) we changed the player to(works for RED but not YELLOW or BLUE)... so lost.
This is my first "serious" project. Going beyond the tutorials and making something "mine." I would love to get this right. :)
Code below.
COLLISION
void OnTriggerEnter(Collider o)
{
if(o.gameObject.tag == "PickUp")
{
if(o.renderer.material.color==Color.black)
{
LoadNextLevel();
}
if(o.renderer.material.color==Color.yellow)
{
TargetUI = "YELLOW";
}
if(o.renderer.material.color==Color.red)
{
TargetUI = "RED";
}
if(o.renderer.material.color==Color.blue)
{
TargetUI = "BLUE";
}
o.gameObject.SetActive(false);
playerColor = o.renderer.material.color;
SetPlayerColor();
SplatSFX.Play();
SetTargetText();
}
TEXT CHANGE
void SetTargetText()
{
TargetText.text = TargetUI;
}
Any ideas? Any way I can make the situation clearer to get help? I am lost.
Did you try logging the values of 'o.renderer.material.color'?
Because you really have to narrow down your search first. I believe you say that 'targetUI = "RED"' works. But 'TargetUI = "BLUE"' and 'TargetUI = "YELLOW"' don't work or are never called...
If this is the case, then doing this should help you figure out what the problem is:
// Add a log first to check the value you have
Debug.Log(o.renderer.material.color);
if(o.renderer.material.color==Color.yellow)
{
TargetUI = "YELLOW";
}
if(o.renderer.material.color==Color.red)
{
TargetUI = "RED";
}
if(o.renderer.material.color==Color.blue)
{
TargetUI = "BLUE";
}
The result of that log is important, as I assume it is never [0,0,1,1] (blue) but sometimes [1,0,0,1] (red). If this is true then I can't tell why, sinse the code provided by you does not contain the part where you set this value. ('o.renderer.material.color').
Your answer
Follow this Question
Related Questions
Changing the font size of GUIText (on Unity iPhone)? 1 Answer
GUI Text line break Alt+Enter doesn't work 1 Answer
How do i make a text box appear on screen after a chest has been opened? 3 Answers
How to parent a GUI text to current game object 3 Answers
In game message displayed on GUI - text and texture 1 Answer