Hi, fellow unity programmers.
As shown in the code below it is obvious i am a beginner at coding (2 days coding js). I require a script that shoots a bullet for me, i have attempted and i think i did well but as shown in the code i narrowed it down to the last function to fire however i don’t know what lines of code actually shoot the bullets .It would be appreciated if someone helped me figure out what to put in the Fire function. Also as is shown i use a really dodgy way of putting a shoot delay on the weapons, i want to ask whether this will lag a game when used in mass such as in multiplayer. If so, could someone please redirect me to a better way of restricting the user to spam click.
Thanks in advance - Jake
#pragma strict
var wep = "pistol";
var mags = 5;
var rounds = 30;
var wait = 0.1;
var wepwait = 0.3;
function Start () {
Repeat();
}
function Update () {
CheckReload();
UpdateWait();
if (Input.GetButton("Fire1")) {
if (wait > wepwait) {
if (rounds > 0) {
wait = 0;
Fire();
}
}
}
}
function Repeat () {
yield WaitForSeconds(0.01);
AddSec();
}
function AddSec () {
wait = wait + 0.01f;
Repeat();
}
function UpdateWait () {
if (wep == "pistol") {
wepwait = 0.3;
}
else {
if (wep == "shotgun") {
wepwait = 1.1;
}
else {
if (wep == "rifle") {
wepwait = 0.1;
}
else {
if (wep == "lmg") {
wepwait = 0.01;
}
}
}
}
}
function CheckReload () {
if (rounds < 1) {
if (mags > 0) {
mags--;
//insert reload anim here :P
yield WaitForSeconds(0.0); //how long the anim is
rounds = rounds + 30;
}
}
}
function Fire () {
// please tell me what to put in here to fire a bullet
}