Is there a better way of permanent change a value for a variable in a script, lets say after you touched a trigger? This works but I don’t like the part when I test for the value, before I actually give it a value:
var cangeValuePermanet : boolean;
function Update() {
if (cangeValuePermanet != true) { // wops!?
cangeValuePermanet = false;
}
}
function SomethingHappend() { // called from a trigger maybe
cangeValuePermanet = true;
}
If I start the script with: var cangeValuePermanet : boolean = false; then it will be reset to false every time, and thats not wat I want.
That code in your update is not needed. Whenever you initialize an object with a script attached to it, the values get set to whatever you set them to be in your script or in the inspector. You will have to provide a bit more detail about what you want to achieve, so I know what code you need.
var cangeValuePermanet : boolean = false;
function SomethingHappend() { // called from a trigger maybe
cangeValuePermanet = true;
}
Then cangeValuePermanet = true. But next time Unity read the script it start at the top and cangeValuePermanet are reset back to false with this line:
var cangeValuePermanet : boolean = false;
Right?
And that’s what I don’t want to happend, I want cangeValuePermanet to be false every time Unity reads it. But after I touched a trigger, I wan’t cangeValuePermanet to be true every time the script run.
Maybe I don’t manage to tell what I am trying to in a good way… Ok, but what I’m try to archive is this:
Every time Unity runs the script, variable cangeValuePermanet has to be false
After I touched a trigger:
Every time Unity runs the script, variable cangeValuePermanet has to be true…
I am kind of new to scripting so maybe I’m missing something important… these scripts are run many times each second right? How can cangeValuePermanet continue to be true every time it’s run, if you start the script by saying cangeValuePermanet = false?
if you change the value to be false, then it is false until you change it back, it doesnt go back to the original value until you “Restart” the program or whatever.
Runs the script? Well, they are not run many times each second, the function “Update” is called many times each second.
If you change ‘cangeValuePermanet’ to true, it will be true until you change it to false or you exit Play mode.
Ok… then I misunderstood… Only Update is called many times each second, and the variables outside Update are only read ones. Thanks for clearing things up for me.