- Home /
rocket Launcher GUI Text probleme
i got a rocket launche script attach to a GUI text that keep track of whats the max ammo and whats my ammo left but my ammo left in the GUI text does not go down as i shoot the misslie but it goes down in the inspector. what am i doing wrong????
here is my rocket launcher script:
var projectile : Rigidbody; var initialSpeed = 20.0; var reloadTime = 0.5; var ammoCount = 5; var maxAmmo =5; var guiTextMissile : GUIText; private var lastShot = -10.0;
guiTextMissile.text = ammoCount +"/" + maxAmmo;
function Fire () { // Did the time exceed the reload time? if (Time.time > reloadTime + lastShot && ammoCount > 0) { // create a new projectile, use the same position and rotation as the Launcher. var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));
// Ignore collisions between the missile and the character controller
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
lastShot = Time.time;
ammoCount--;
}
}
Answer by StephanK · Oct 23, 2010 at 08:50 AM
You have to update the text of the guiText component manually. Just copy the line where you initialize guiTextMissile.text to the line right after ammoCount--;