Less of a question and more of a rant. Of all the things coding can do why on earth can it NOT handle a simple line like:
if( thisNumber = 1)
thisScript.enabled = true;
I am trying to enter a triggerZone and upon doing so will randomly enable one of 4 scripts.
So I enter the zone and randomly generate a number and I want that randomly generated number to enable a corresponding script ( like in the code above). Why is this such an impossible feat for Unity?!?!
Any answers how to do this rudimentary request?
If you are using a float, it isn’t likely to have a value of 1. Float is a decimal number, and as such, it can have a lot of values if you are using ‘Random.Range()’, for example.
Try using an integer, which will always be a whole number.
int number = Random.Range(0, 4);
if(number == 0) thisScript.enabled = true;
else if(number == 1) thatScript.enabled = true;
// And so on...
Thanks, actually “float” was just what I attempted after “int” wasn’t working. So I changed it back to “int” but I think the key is that ==. I thought for sure I tried that as well and got an error saying I couldn’t use it. It works now and thanks for the (0,4) advice . I was wondering why it never randomly picked 1.
so …yeah! now my enemy randomly picks 1 of 4 behaviours
so he’s not so easy to kill