private void MyInput()
{
// check if allowed to hold down button
if (allowButtonHold) shooting = Input.GetKey(KeyCode.Mouse0);
else shooting = Input.GetKeyDown(KeyCode.Mouse0);
//reloading
if(Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !reloading) Reload();
if (readyToShoot && shooting && !reloading && bulletsLeft <= 0) Reload();
if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
{
//set bullet shots to 0
bulletsShot = 0;
Shoot();
}
}
For the obvious reasons. You just have to change the code in the usual way and make it correct so that it will work.
“not woring” is not a problem description
you need to tell us what’s wrong with that script
Perhaps because you wrote a bug! Don’t do that. You’ll need to fix all your bugs and typing mistakes before it will work, and we cannot do that for you.
That means it is… time for you to to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...);
statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
Two steps to tutorials and / or example code:
- do them perfectly, to the letter (zero typos, including punctuation and capitalization)
- stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
Imphenzia: How Did I Learn To Make Games: