FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionFull Auto/BurstFire Gun Modes?????

more_horiz
Hi does anyone know how to make a full auto gun in unity 5.0?? if so, please post an example of a script!!!!!!!

descriptionRe: Full Auto/BurstFire Gun Modes?????

more_horiz
or a burstfire mode too

descriptionRe: Full Auto/BurstFire Gun Modes?????

more_horiz
Here is an example of something that you may like:

Code:

private var burst : boolean;
private var full : boolean;
function Start () {

}

function Update () {
if(Input.GetKeyDown(KeyCode.F)) {
burst = true;
full = false;
}
if(Input.GetKeyDown(KeyCode.G)) {
   full = true;
   burst = false;
}

if(full == true && Input.GetMouseButtonDown(0)) {
   
}
if(burst== true && Input.GetMouseButtonDown(0)) {
   
}
}

I do not know which part your are trying to get at...the firing code or setting up booleans
this is in JavaScript by the way

-BryceCain25
Smile

_________________
-BryceCain25

descriptionRe: Full Auto/BurstFire Gun Modes?????

more_horiz
Thanks Man!

descriptionRe: Full Auto/BurstFire Gun Modes?????

more_horiz

Sorry I didn't clarify which one Razz
I would like the firing + damage code

descriptionRe: Full Auto/BurstFire Gun Modes?????

more_horiz
Using damage in combination would be pretty simple.
Just when you are firing do something like this:



Code:

private var burst : boolean;
private var full : boolean;
private var bulletsPerSecond = null; //replace null with a number you'd like
public var Physicsbullet : Rigidbody; //make sure there is a rigidbody
//attached
public var speed : int;
private var time : int;
function Start () {
InvokeRepeating("Shoot", 0.0, bulletsPerSecond);
}

function Update () {
if(Input.GetKeyDown(KeyCode.F)) {
burst = true;
full = false;
}
if(Input.GetKeyDown(KeyCode.G)) {
  full = true;
  burst = false;
}

if(full == true && Input.GetMouseButtonDown(0)) {
  bulletsPerSecond = null; //use a larger number than one on this variable
}
if(burst== true && Input.GetMouseButtonDown(0)) {
  bulletsPerSecond = 1; //we set this to 1 bullet per press
}



}

function Shoot () {
   Instantiate(Physicsbullet, transform.position, transform.rotation);
   Physicsbullet.AddRelativeForce(Vector3.forward * speed);

}


if this does not work or compile correctly, tell me please! I am glad to help you as much as possible!


_________________
-BryceCain25

descriptionRe: Full Auto/BurstFire Gun Modes?????

more_horiz
K thanks Man! Really apriecate the help! lol bad at spelling Razz

descriptionRe: Full Auto/BurstFire Gun Modes?????

more_horiz
ok im going to sound like an idiot when I ask this but what do I assign the rigid body to?

descriptionRe: Full Auto/BurstFire Gun Modes?????

more_horiz
@coolc wrote:
ok im going to sound like an idiot when I ask this but what do I assign the rigid body to?
You set the rigidbody to the bullet you have as a mesh...this rigidbody has physics properties attached to it...so assign a bullet mesh that has a rigidbody attached to it...it will allow the engine to apply certain raycasts (think of them like little lasers, and laser sensors) to be sent out from the gun muzzle (object you placed this script on) and send out a signal, if a signal is received from another object in the scene that is scripted to wait for these kinds of events to happen to them. Once this happens a certain event will happen, in this case you can apply damage.

And about the spelling; no worries, spelling is none of the issue, and I have no problem with it Smile

-BryceCain25
=)

_________________
-BryceCain25
Permissions in this forum:
You cannot reply to topics in this forum