Bullethole doesn't instantiate

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

You’re raycsting thrice. You only need to do it once, and then you can cache the results. A raycast is a relatively costly operation to do more than once for no reason. Try:

bool bHit = Physics.Raycast(transform.position,transform.forward,hit,BulletRange);

if (bHit && ....)
{
    ....
}
else if (bHit && ....)
{
    ....
}

As for your instantiation problem, if your log says the wall was hit, maybe the decal is spawned with the wrong orientation? Check the hierarchy view to see if it was spawned, then locate it in the scene view and see what’s happening with the object.

EDIT: Oh, now I see. Your bullet hole object is a texture. You can’t directly spawn a texture into the world. You’ll need to have a gameobject with a quad mesh and a mesh renderer and assign the texture to that object. Better yet, you can make it into a prefab. You can either change your code like this:

var BulletHole: GameObject;

Or you could do this (sorry it’s in C#, I don’t know UnityScript, nor am I planning to learn it):

Texture BulletHole;
Mesh DecalMesh;

...

var GO = new GameObject("Decal");
GO.transform.position = hit.point;
GO.transform.rotation = Quaternion.LookRotation(hit.normal);
GO.AddComponent<MeshFilter>().mesh = DecalMesh;
var Mat = new Material(Shader.Find("Unlit/Texture")); // or whatever shader you want to use for the decal
Mat.mainTexture = BulletHole;
GO.AddComponent<MeshRenderer>().material = Mat;

Unnecessarily complex, as you can see. The prefab is the way to go if you ask me.