Hey guys, just wondering how I could do this. Basically I have my script that fires a bullet (click the left mouse button to fire the bullet). Everything is fine and the bullet fires like normal. However, I want another even to occur. Once the bullet is travelling, if the left mouse button is pressed for a second time, I want the bullet to stop moving (freeze) and stay in the environment permanently. So first click = fire a bullet. Second click freeze the force and keep the bullet in the scene.
After this event has occurred, I need the third click to go back to the start and fire another bullet. What’s the best way of doing this guys? Here’s what I have so far:
var bulletPrefab : Transform; // Declares the bullet prefab.
var shotDelay1 : boolean = false;
var counter : int = 1;
// If the space bar is pressed, fire a bullet with a force of 5000 along the Z axis. Once fired, initiate the delay and disable the function for 2 seconds.
function Update ()
{
if (Input.GetMouseButtonDown(0) && shotDelay1 == false)
{
counter ++;
PlatformFire = Instantiate(bulletPrefab, GameObject.Find("SpawnPoint").transform.position, transform.rotation);
PlatformFire.rigidbody.AddForce(PlatformFire.forward * 10000);
shotDelay1 = true;
shotDelay();
if (counter == 2 && Input.GetMouseButtonDown(0))
{
PlatformFire.rigidbody.velocity = Vector3.zero;
}
if (counter > 2)
{
counter = 1;
}
}
}
function shotDelay()
{
if (shotDelay1 == true)
{
yield WaitForSeconds (0.6);
shotDelay1 = false;
}
}
Thanks for any tips