- Home /
Why doesn't my script work?
So basically i created a script that will toggle whether or not the camera's image effect grayscale will be toggled.. I don't care about the actually "isGrayscale boolean" as of yet... I am more interested in the actual toggling of the button Textures... Basically when i click the button on-screen, the texture changes from the standardButton, to the buttonChecked.. But when i click it again, it just won't work?? Here is the script:
var standardButton : Texture;
var buttonChecked : Texture;
static var isGrayscale : boolean = false;
private var isChecked : boolean = false;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function OnMouseDown () {
if(isChecked == true){
isChecked = false;
isGrayscale = false;
renderer.material.mainTexture = standardButton;
}
if(isChecked == false){
isChecked = true;
isGrayscale = true;
renderer.material.mainTexture = buttonChecked;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Answer by jabez · Oct 26, 2014 at 02:05 AM
try a else statement after the first is checked instead of checking if its set to false, because at the moment as soon as you set ischecked to true it gets set to false automatically then it loops back & forth.
Actually i have another problem.. Now that i have done this script.. I have made another script where i want to refer to the global variable i created in this one. Do know how i do that?
you would have to use something like
var script : yourscriptname ;
script = gameObject.GetComponent(yourscriptname);
script.isGrayscale = false;
var copybool : boolean ;
copybool = script.isGrayscale;
but the script has to be attached to the same gameobject . sorry i dont really use javascript so i had to edit it a few times
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
What's the best way to create a gui slider that will change the image on screen? 1 Answer
Is anyone able to fix my code? 3 Answers
Need code help from smart people 1 Answer
Raycast question 1 Answer