- Home /
Automatic fire in weapons
Im currently away from home and cant test this, but im asking anyway in case i have to ask anyway later.(on mobile at school.) i've been wondering about how to do an automatic weapon, and i'm asking will the following work to make it full auto? Script isn't precise.
Var isitshooting : boolean = false;
Var firerate : float = 0.1; // makes the gun shoot ten times per second
Function fire(){
//stuff that makes it shoot
//i'll put here later
//this function is the one that shoots
}
Function Start() {
invokerepeating("checkiffiring",0,firerate);
}
Function checkiffiring() {
If(isitshooting == true) {
fire();
}
}
Function on.keydown(mouse0) () { //pressing the first mouse button, pretend it's correct.
isitfiring = true;
}
Function on.keyup(mouse0) () { // releasing the mouse button
isitfiring = false;
}
Again, im on mobile so The script has syntax errors but the jist of the script is what im wondering about
Plenty of shooting scripts laying around this site for you to browse for how to do this.
One could probably piece together an entire (working, but maybe a little screwy in places) game just by using code from this site and the unity forum without having to modify any of it.
I usually try not to use other peoples scripts though, its mostly pride reasons.
Don't use their scripts then. Learn from them. 4 is the answer to 2+2 whether we tell you it in this topic or you find it in another one.
The point of the question though, is will it work, and if not, why.
Answer by T-D-M-3 · May 08, 2014 at 01:17 AM
There is a completed script for this here:
there is also a bunch of other useful stuff!
Your answer
Follow this Question
Related Questions
How to smooth aiming? 1 Answer
GetComponentInChildren(Renderer).active wont work? 2 Answers
Javascript version of 'Mouse look' script? 1 Answer
Disable Script 1 Answer
Instantiate cloned prefab to local position of an empty object 1 Answer