- Home /
how to make something not be equal to a value
hi, so i have a script to check if there is a texture in a gui box, and if there isn't another box won't be equal to that texture. I.E.
if(BoxTexture != Blank)
{
if(BoxTexture == CopperTexture)
{
OtherBox == CopperTexture;
}
}
i would like to then make OtherBox not equal to the Copper Texture if the texture has been removed? is there a way to do this like :
OtherBox != CopperTexture?
What do you want it to be set to if the texture is removed? a blank texture? a different texture?
Unfortunately, you cannot use != to set the value of something not equal to something else. Ins$$anonymous$$d, you have to use = to set the value to something else
Answer by HalversonS · Apr 11, 2014 at 04:09 PM
I tested with Destroy(ThatBox); rather than setting up a texture comparison, so you'll have to change it, but it functions.
#pragma strict
var ThisBox : GameObject;
var ThatBox : GameObject;
function Start()
{
ThisBox = GameObject.Find("BoxTexture");
ThatBox = GameObject.Find("OtherBox");
}
function Update()
{
if(ThisBox.renderer.material.mainTexture != null)
{
if(OtherBox.renderer.material.mainTexture == "CopperTexture");
//if(renderer.material.mainTexture == ("CopperTexture"))
{
ThatBox.renderer.material.mainTexture = "SomeDefaultTexture";
//or remove the texture.
}
}
}
You'll have to find your correct textures obviously and set them up. If you want to not use CopperTexture you could build an array to assign a different texture to the object and exclude CopperTexture from the list. Although... depending on how many resources you have that could slow things down (target platform?).
Thanks for the answer , but i think i found a way around the problem. thanks anyway!
Your answer
Follow this Question
Related Questions
Why is my collision function not calling my method inside of it? 1 Answer
help understanding variables created in an if statement vs up top 2 Answers
Only able to jump when grounded.,Only doing something if something is true 1 Answer
Use a #if statement to check if a script exists in project? 0 Answers
if statement not working 2 Answers