Im trying to get my bullets left to display on my screen already went through fps tutorial but it seems to be no help for me. It shows up and inspecter view but i cant get it on the screen. here is what i got so far.
var Range : float = 1000;
var Force : float = 1000;
var Clips : int = 20;
var BulletPerClip : int = 50;
var ReloadTime : float = 3.3;
var Damage : int = 20;
var BulletsLeft : int = 0;
var shootTimer : float = 0;
var shootCooler : float = 0.06;
public var ShootAudio : AudioClip;
public var ReloadAudio : AudioClip;
var HitParticles : ParticleEmitter;
var MuzzleFlash : ParticleEmitter;
var MuzzleCooler : float = 0.06;
var MuzzleFlashTimer : float = 0;
var light1 : GameObject;
var light2 : GameObject;
var light3 : GameObject;
var MuzzleSpeed : int = 200000;
var KeyTimer : float = 0;
var KeyCooler : float = 1;
function Start (){
BulletsLeft = BulletPerClip;
MuzzleFlash.emit = false;
HitParticles.emit = false;
}
function Update () {
if( KeyTimer > 0){
KeyTimer -= Time.deltaTime;
}
if( KeyTimer < 0){
KeyTimer = 0;
}
if( MuzzleFlashTimer > 0){
MuzzleFlashTimer -= Time.deltaTime;
MuzzleFlashShow();
}
if( MuzzleFlashTimer < 0){
MuzzleFlashTimer = 0;
}
if( shootTimer > 0){
shootTimer -= Time.deltaTime;
}
if( shootTimer < 0){
shootTimer = 0;
}
if( KeyTimer == 0){
if(Input.GetKey(KeyCode.F) && BulletsLeft){
if( shootTimer == 0){
PlayShootAudio();
RayShoot();
shootTimer = shootCooler;
}
if( MuzzleFlashTimer == 0){
MuzzleFlashTimer = MuzzleCooler;
MuzzleFlashShow();
}
}
}
}
function MuzzleFlashShow (){
if( MuzzleFlashTimer > 0){
MuzzleFlash.emit = false;
light1.active = false;
light2.active = false;
light3.active = false;
}
if( MuzzleFlashTimer == MuzzleCooler ){
MuzzleFlash.transform.localRotation = Quaternion.AngleAxis( Random.value * 360 * MuzzleSpeed , Vector3.forward);
MuzzleFlash.emit = true;
light1.active = true;
light2.active = true;
light3.active = true;
}
}
function RayShoot (){
GameObject.Find("FPS_m16_01").animation.Play("m16_fire");
var Hit : RaycastHit;
var DirectionRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position , DirectionRay * Range , Color.blue);
if(Physics.Raycast(transform.position , DirectionRay , Hit, Range)){
if(Hit.rigidbody){
if( HitParticles){
HitParticles.transform.position = Hit.point;
HitParticles.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, Hit.normal);
HitParticles.Emit();
Hit.rigidbody.AddForceAtPosition( DirectionRay * Force , Hit.point);
Hit.collider.SendMessageUpwards("ApplyDamage" , Damage , SendMessageOptions.DontRequireReceiver);
}
}
}
BulletsLeft --;
if(BulletsLeft < 0){
BulletsLeft = 0;
}
if(BulletsLeft == 0 ){
Reload();
}
}
function Reload (){
PlayReloadAudio();
GameObject.Find("FPS_m16_01").animation.Play("m16_reload");
yield WaitForSeconds( ReloadTime);
if(Clips > 0){
BulletsLeft = BulletPerClip;
}
}
function PlayShootAudio(){
audio.PlayOneShot( ShootAudio);
}
function PlayReloadAudio(){
audio.PlayOneShot( ReloadAudio);
}