Hello I am having trouble with Random.Range not working as shown in the video. I’m probably just overlooking something blindingly obvious as normal. If you have any suggestions or solutions let me know.
Here is the code I am using.
SHOOTER.CS
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
I dont know what you changed in the editor, or what exactly your problem is;
but if you did not change the value of “firingRateVariance”
it would be zero and nothing wil be deducted or added,
so then the numbers u use to get a random between are the same.
Well I followed what was shown in the video and the firingRateVariance was set to 0 in the code but changed later in the inspector.
The issue seems to be that Random.Range just isn’t accepted as an option where it is in the code. It is underlined by a red squiggly line and any solutions offered by Visual Studio don’t resolve the issue. I can’t find any spelling errors or other problems that would result in Random.Range not being accepted.
It is because you are using System;andusing UnityEngine;. Random exists in both namespaces and Visual Studio can’t guess which one you want to use. I don’t really see a need for System so just remove it
Sometimes you may need to be using both System and UnityEngine. In those cases you’d have to fully qualify it by writing UnityEngine.Random.Range(...) (or System.Random depending on which one you want to use).
Another option I’ve seen once was to alias the Random you want to use, essentially removing the other
using Random = UnityEngine.Random;
Also, if you hover over the red squiggly it will (should) tell you that Random is ambiguous between UnityEngine.Random and System.Random
The error on the bottom tells you the issue. It cannot tell if you’re talking about UnityEngine.Random.Range and System.Random.Range. The issue happens when you have both using UnityEngine and using System.
Change it to UnityEngine.Random.Range and you should be good to go.
[Damn, didn’t see Bix’s reply before I posted. Whoops]