- Home /
Shooting speed help!
I shoot about 10 shots per second, but i want to change that! for example to one per second, need help! can you help me with reloading too? THANK YOU VERY MUCH!!!
Script;
var projectile : Rigidbody; var speed = 20;
function Update () {
if(Input.GetButton("Fire1")) {
clone = Instantiate(projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection(Vector3(0,0,speed));
Destroy(clone.gameObject,3);
}}
One curious question abut this?. What if the player hit the fire button many times within that second?, are the other clicks going to be ignored, and just the first one should create the bullet?
Answer by ShadowAngel · Nov 14, 2012 at 08:24 PM
var LastShootTime : float = 0.0;
var AttackSpeed : float = 1.0;
if (LastShootTime + 1/AttackSpeed < Time.time)
{
LaunchProjectile();
LastShootTime = Time.time;
}
AttackSpeed is how many shoots you want in one second.
Cos its my function... You need to write you own. Like this one.
function LaunchProjectile() {
if(Input.GetButton("Fire1")) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0,0,speed));
Destroy(clone.gameObject,3);
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Ammo with ammobar problem. 0 Answers
Bullets sometimes shoot under map 1 Answer