var Damage = 10;
var FireRate = 0.1F;
var NextFire = 0.0F;
var BulletRange = 200;
var Enemy : GameObject;
var GunFireSound : AudioClip;
var Clip = 30;
var TotalBullets = 300;
var ReloadTime = 3;
var BulletHole : Texture;
function Update() {
if(Input.GetButton("Fire1") && Time.time > NextFire && Clip > 0){
NextFire = Time.time + FireRate;
GetComponent.<AudioSource>().clip = GunFireSound;
GetComponent.<AudioSource>().time = 0.2f;
GetComponent.<AudioSource>().Play();
Rayshooting();
Clip --;
}
else if(Clip == 0){
Reload();
}
if(Input.GetKey(KeyCode.R) && Clip < 30) {
Reload();
}
}
function Rayshooting() {
Debug.DrawRay(transform.position,transform.forward * BulletRange);
var hit : RaycastHit;
Physics.Raycast(transform.position,transform.forward,hit,BulletRange);
if (Physics.Raycast(transform.position,transform.forward,hit,BulletRange)&&hit.transform.gameObject == Enemy){
hit.transform.SendMessage("DamageTaken", Damage, SendMessageOptions.DontRequireReceiver);
}
if (Physics.Raycast(transform.position,transform.forward,hit,BulletRange)&&hit.transform.gameObject.tag == "Buildings" || "Terrain"){
Debug.Log("Hit wall!");
Instantiate(BulletHole, hit.point, Quaternion.LookRotation(hit.normal));
}
}
function Reload() {
yield WaitForSeconds(ReloadTime);
var Swap = 0;
if(TotalBullets > 0){
if(Clip != 0) {
Swap = 30 - Clip;
Clip = Clip + Swap;
TotalBullets = TotalBullets - Swap;
}
else if(Clip == 0){
TotalBullets -= 30;
Clip += 30;
}
}
else {
Debug.Log("Out Of Ammo!");
}
}
this is my shooting script right now (the reloading part isn’t totally done yet) but I’m trying to get a bullethole at the point of hit as you can see but the bullethole does not instantiate. the code however does return the Hit wall to the debug log. can someone tell me what’s wrong because it’s frustrating because I’m not getting any error whatsoever
thanks