The question is answered, right answer was accepted
If/elseif code doesn't seem to work
The code I have has 4 variables that it checks for:
var BaseTexture : Texture;
var GreenTexture : Texture;
var RedTexture : Texture;
var BlueTexture : Texture;
var OrangeTexture : Texture;
function Update () {
var GreenCheck : boolean;
var RedCheck : boolean;
var BlueCheck : boolean;
var OrangeCheck : boolean;
GreenCheck = GreenCollect.GreenActive;
RedCheck = RedCollect.RedActive;
BlueCheck = BlueCollect.BlueActive;
OrangeCheck = OrangeCollect.OrangeActive;
if (GreenCheck==true) {
this.GetComponent.<Renderer>().material.mainTexture = GreenTexture;
GreenCheck=false;
}
if (RedCheck==true) {
this.GetComponent.<Renderer>().material.mainTexture = RedTexture;
RedCheck=false;
}
if (BlueCheck==true) {
this.GetComponent.<Renderer>().material.mainTexture = BlueTexture;
BlueCheck=false;
}
if (OrangeCheck==true) {
this.GetComponent.<Renderer>().material.mainTexture = OrangeTexture;
OrangeCheck=false;
}
}
This code doesn't seem to work, as it only changes the texture once or twice (sometimes three times, it seems to work based on the code order). I have tried while statements, and elseif statements with this code as well, and they do not work every time.
This code is applied to all the walls and floors that require texturing as a result of this code.
An example of a Collect JS that I have is as follows:
static var GreenActive : boolean = false;
function OnTriggerEnter (info : Collider) {
GreenActive=true;
this.Destroy(gameObject);
}
This code is applied to separate objects, as these are the triggers.
My question is: How do I get the first code to work every time, in which it changes the texture every time?
Answer by BartandLees · Apr 16, 2017 at 07:34 PM
FIxed!
I simply added a [ScriptHere].[Color]Active=false; which disabled the triggers so they wouldn't always be turned on.
Example code:
static var GreenActive : boolean = false;
function OnTriggerEnter (info : Collider) {
GreenActive=true;
OrangeCollect.OrangeActive=false;
BlueCollect.BlueActive=false;
RedCollect.RedActive=false;
this.Destroy(gameObject);
}