Question by
overlordyigit1 · Jun 01, 2016 at 06:06 AM ·
multipleboatcannoncannonball
shooting multiple cannons with delay
hey,im trying to shot from broadside.i have script in empty gameobject that shot and reload but if i use the script multiple gun,when i shoot all the ball goes same time. i wanna make shot cannons with order (like shot all cannons in 2 second with in random time each other)
unity.png
(10.0 kB)
Comment
var $$anonymous$$axAmmo = 1;
var Ammo = $$anonymous$$axAmmo;
var Bullets = 15;
var Bullet : GameObject;
var FirePoint : GameObject;
private var timer = 0.0;
var reloadTime = 2.0;
var Fire : String = "$$anonymous$$usketFire";
var reloading : boolean;
function Start ()
{
}
function Update ()
{
if(Ammo > 0 && Input.Get$$anonymous$$ouseButtonDown(1) && Fire == "$$anonymous$$usketFire")
{
FireOneBullet();
}
else if(Input.Get$$anonymous$$ey("r"))
{
Reload();
}
else if(reloading) {
if(timer<reloadTime)
{
timer+=Time.deltaTime;
}
else
timer=0.0;
if(timer>=reloadTime)
{
Ammo ++;
Bullets --;
timer=0.0;
reloading = false;
}
}
}
function FireOneBullet ()
{var projectile = Instantiate(Bullet,transform.position,transform.rotation);projectile.GetComponent.<Rigidbody>().AddForce(transform.right * 10000);//cannon's x axisPhysics.IgnoreCollision(projectile.collider, collider);
// var Bullet = Instantiate(Bullet, FirePoint.transform.position, transform.rotation);
Ammo --;
if(Ammo < $$anonymous$$axAmmo && Bullets > 0)
{
reloading = true;
}
}
function Reload ()
{
if(Ammo < $$anonymous$$axAmmo && Bullets > 0)
{
reloading = true;
}
}
Best Answer
Answer by Guhanesh · Jun 01, 2016 at 02:35 PM
add yield WaitForSeconds (Random.Range(0.0f,0.5f)); before bullet instantiation script.
function FireOneBullet ()
{
yield WaitForSeconds (Random.Range(0.0f,0.5f));
var projectile = Instantiate(Bullet,transform.position,transform.rotation);projectile.GetComponent.<Rigidbody>().AddForce(transform.right * 1000);//cannon's x axisPhysics.IgnoreCollision(projectile.collider, collider);
// var Bullet = Instantiate(Bullet, FirePoint.transform.position, transform.rotation);
Ammo --;
if(Ammo < MaxAmmo && Bullets > 0)
{
reloading = true;
}
}
Your answer
Follow this Question
Related Questions
cannon wont fire on vertical axis! 0 Answers
Cannons wont move on the vertical axis 0 Answers
How to shoot cannon ball in 2d? 0 Answers
Find Number Multiple within Range 0 Answers
GUI Text showing even if the 'if' statement is not met 1 Answer