- Home /
Question by
predatordpc · Jun 02, 2013 at 03:55 PM ·
fpsautomatedtower
Hello guys I made combined simple code from codes i found on unity forums (I suck at programming) ^^, but i have a problem my tower was shoting repeating after 2 secs but it stopped and i don't know how to make this back can you help me?
here is the code:
#pragma strict
// Starting in 2 seconds.
// a projectile will be launched every 0.3 seconds
var projectile : Rigidbody;
InvokeRepeating("LaunchProjectile", 2, 5.0);
var speed = 60;
function LaunchProjectile () {
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );
CancelInvoke();
audio.Play();
// Delay a clip by 1 sec (44100 samples)
audio.Play(44100);
}
How to fix this? help! :c
Comment
Best Answer
Answer by predatordpc · Jun 02, 2013 at 09:30 AM
Found solution!
#pragma strict
var speed = 30;
// Starting in 2 seconds.
// a projectile will be launched every 0.3 seconds
var projectile : Rigidbody;
InvokeRepeating("LaunchProjectile", 2, 0.3);
function LaunchProjectile () {
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );
audio.Play();
// Delay a clip by 1 sec (44100 samples)
audio.Play(44100);
}
just had to delete CancelInvoke(); dunno why it was there, i will leave it so other makers will be able to use it in their games ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613103342im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
new to scripting need some fps controll help plz :) 2 Answers
Specs to keep whie making a PC game? 2 Answers
what is wrong with this online FPS script(not done) ? 1 Answer
FPS Ai help 1 Answer