Question by
Aligrid · Sep 13, 2015 at 02:06 PM ·
javascript
I think that everything is all right...why it doesnt work correctly?
// The speed the bullet moves
var Speed : float = 0.4;
// The number of seconds before the bullet is automatically destroyed
var SecondsUntilDestroy : float = 10;
private var startTime : float;
function Start () {
startTime = Time.time;
}
function FixedUpdate () {
// Move forward
this.gameObject.transform.position += Speed * this.gameObject.transform.forward;
// If the Bullet has existed as long as SecondsUntilDestroy, destroy it
if (Time.time - startTime >= SecondsUntilDestroy) {
Destroy(this.gameObject);
}
}
function OnCollisionEnter(tc : Collision) {
// Remove the Bullet from the world
Destroy(this.gameObject);
}
Comment
Your answer
Follow this Question
Related Questions
How get position from a game object? 5 Answers
Help converting a few lines of JS to C#. 1 Answer
how to Increase speed of a car.? 0 Answers