Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » General Dicussions » Full Auto/BurstFire Gun Modes?????

Full Auto/BurstFire Gun Modes?????

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Full Auto/BurstFire Gun Modes????? on Tue Apr 14, 2015 7:39 pm

coolc


Member [Lv. 2]
Member [Lv. 2]
Hi does anyone know how to make a full auto gun in unity 5.0?? if so, please post an example of a script!!!!!!!

View user profile

2 Re: Full Auto/BurstFire Gun Modes????? on Tue Apr 14, 2015 7:44 pm

coolc


Member [Lv. 2]
Member [Lv. 2]
or a burstfire mode too

View user profile

3 Re: Full Auto/BurstFire Gun Modes????? on Tue Apr 14, 2015 11:10 pm

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
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

View user profile

4 Re: Full Auto/BurstFire Gun Modes????? on Wed Apr 15, 2015 2:54 pm

coolc


Member [Lv. 2]
Member [Lv. 2]
Thanks Man!

View user profile

5 Re: Full Auto/BurstFire Gun Modes????? on Wed Apr 15, 2015 2:59 pm

coolc


Member [Lv. 2]
Member [Lv. 2]

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

View user profile

6 Re: Full Auto/BurstFire Gun Modes????? on Wed Apr 15, 2015 4:39 pm

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
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!

View user profile

7 Re: Full Auto/BurstFire Gun Modes????? on Wed Apr 15, 2015 7:07 pm

coolc


Member [Lv. 2]
Member [Lv. 2]
K thanks Man! Really apriecate the help! lol bad at spelling Razz

View user profile

8 Re: Full Auto/BurstFire Gun Modes????? on Wed Apr 15, 2015 7:24 pm

coolc


Member [Lv. 2]
Member [Lv. 2]
ok im going to sound like an idiot when I ask this but what do I assign the rigid body to?

View user profile

9 Re: Full Auto/BurstFire Gun Modes????? on Wed Apr 22, 2015 5:47 pm

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
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
=)

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum