- Home /
SCRIPT NOT WORKING
My turret is supposed to look and shoot one fireball a second at my character. It is looking and shooting, but a spray forever. What is going wrong? Please help! I NEED HELP AS SOON AS POSSIBLE
var LookAtTarget : GameObject; var damp = 6.0; var bulletPrefab : Transform; var savedTime=0;
function Update () { if(LookAtTarget) { var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
var seconds : int = Time.time;
var oddeven = (seconds % 2);
if(oddeven)
{
Shoot(seconds);
}
}
} function Shoot(seconds) { if(seconds!=savedTime) { var bullet = Instantiate(bulletPrefab, transform.Find("SpawnPoint1").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * 1000);
savedTime=seconds;
}
}
"SCRIPT NOT WOR$$anonymous$$ING" isn't a question, and could not be any less informative.
Please format the code, before requesting an answer! Please change you title to a Question! Please reformat your sentances so that they are understandable!!!
Answer by gsoft9999 · Feb 14, 2013 at 11:42 PM
var Player : Transform; var lifeTime : float var damp : float; private var timer1 : float;
function Update () { timer+=Time.deltaTime; var rotate = Quaternion.LookRotation(Player.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime damp); if(timer>1.0){ var bullet : Rigidbody; bullet=Instantiate(prefab,transform.position,transform.rotation); bullet.rigidbody.AddForce(transform.forward 1000); Destroy(bullet.gameObject,lifeTime); } }
Please format your code and write a sentace or two... Don't answer a question with just plain, unformatted code
Answer by flaviusxvii · Feb 14, 2013 at 11:38 PM
Here.. now stop with these EMERGENCY!! Questions! You're going to get reported..
var LookAtTarget : GameObject;
var damp = 6.0;
var bulletPrefab : Transform;
var coolDown:float = 1; //Will shoot every second
var coolDownTimer:float = 0; // time since we've shot
function Update ()
{
if(LookAtTarget)
{
var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
coolDownTimer -= Time.deltaTime;
if(coolDownTimer <= 0) {
Shoot();
coolDownTimer = coolDown; // reset the timer
}
}
}
function Shoot()
{
var bullet = Instantiate(bulletPrefab, transform.Find("SpawnPoint1").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * 1000);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can anyone help me with a simple CSharp error 1 Answer
whats wrong with my code? 1 Answer
i need some code suggestions 1 Answer
" ';' expected. Insert a semicolon at the end." Error Help 1 Answer