Hi all
I downloaded Unity FPS tutorial form http://unity3d.com/support/resources/tutorials/fpstutorial.html. Here for machine gun one click 2 or 3 bullets are firing but I need only one, so I increased fireRate variable 0.05 to 0.15 now its working fine, but if I am keep on pressing Its not firing continuously (taking some delay because of more fireRate). How to fix this problem.
I fixed this problem. But I need this for iPhone, here my code
Player.js
if(fireJoystick.tapCount>0){
BroadcastMessage("Fire",true);
}
MachineGun.js
var range = 100.0;
private var fireRate = 0.05;
var force = 10.0;
var damage = 5.0;
var bulletsPerClip = 40;
var clips = 20;
private var reloadTime = 0.5;
var hitParticles : ParticleEmitter;
var muzzleFlash : Renderer;
private var bulletsLeft : int = 1;
private var nextFireTime = 0.0;
private var m_LastFrameShot = -1;
var damageSprite: Transform;
//var player: Transform;
function LateUpdate(){
if(muzzleFlash){
if (m_LastFrameShot == Time.frameCount) {
muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward);
muzzleFlash.enabled = true;
isFiring=false;
if (audio) {
if (!audio.isPlaying){
//if(autoMode)
audio.Play();
//else
// audio.PlayOneShot(oneShort);
}
audio.loop = true;
}
}else{
muzzleFlash.enabled= false;
enabled=false;
// Play sound
if (audio)
{
audio.loop = false;
}
}
}
}
function Fire () {
if (bulletsLeft == 0)
return;
// If there is more than one bullet between the last and this frame
// Reset the nextFireTime
if (Time.time - fireRate > nextFireTime)
nextFireTime = Time.time - Time.deltaTime;
// Keep firing until we used up the fire time
while( nextFireTime < Time.time bulletsLeft != 0) {
FireOneShot();
nextFireTime += fireRate;
}
}
function FireOneShot () {
audio.Stop();
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
var shootPosition: Vector3 = new Vector3(transform.position.x,Screen.height/2,transform.position.z);
// Did we hit anything?
if (Physics.Raycast (transform.position, direction, hit, range)) {
// Apply a force to the rigidbody we hit
if (hit.rigidbody){
hit.rigidbody.AddForceAtPosition(10 * direction, hit.point);
}
var obj: Transform=Instantiate(damageSprite,hit.point,damageSprite.rotation);
}
// Register that we shot this frame,
// so that the LateUpdate function enabled the muzzleflash renderer for one frame
m_LastFrameShot = Time.frameCount;
enabled = true;
}
if I tap once only one bullet should fire, if I pressing continuously it should keep firing, for this its operates on two modes auto and normal modes
here is the code for PC
if(autoMode){
if(Input.GetButton("Fire1")){
Debug.Log("Calling Fire");
BroadcastMessage("Fire");
}
}else{
if(Input.GetButtonDown("Fire1")){
Debug.Log("Calling FireOneShot");
BroadcastMessage("Fire");
}
}
Now I need help for iphone to take the input form touch pad
Plz any one help me