hi, i want to parent my bullet holes to the object they hit so if the object moves the bullet holes move with it and dont get stuck in the air. here’s my code:
#pragma strict
var bulletTex : GameObject[]; // creates an array to use random textures of bullet holes
var clicked = false;
var clicked2 = false;
var pauseMenu = false;
function Start () {
}
function Update () {
var fwd = transform.TransformDirection(Vector3.forward); //casts our raycast in the forward direction
var hit : RaycastHit;
Debug.DrawRay(transform.position, fwd * 100, Color.green); //drays our raycast and gives it a green color and a length of 10 meters
if((Input.GetKeyDown("2"))|(raycast.BulletsLeft == 0)){
clicked = true;
}
if((Input.GetKeyDown("1"))&(raycast.BulletsLeft != 0)){
clicked = false;
}
if(Input.GetKeyDown("escape")){
if(pauseMenu == true){
pauseMenu = false;
if(clicked2 == false){
clicked = false;
} else if(clicked2 == true){
clicked = true;
}
} else if(pauseMenu == false) {
pauseMenu = true;
if(clicked == true){
clicked2 = true;
} else if(clicked == false){
clicked = true;
clicked2 = false;
}
}
}
if(!clicked){
if(Input.GetButton ("Fire1") && Physics.Raycast(transform.position, fwd, hit, 100)){
Instantiate(bulletTex[Random.Range(0,1)], hit.point+0.001*hit.normal, Quaternion.FromToRotation(Vector3.up, hit.normal));
}
}
if(clicked){
if(Input.GetButton ("Fire1") && Physics.Raycast(transform.position, fwd, hit, 100)){
Instantiate(bulletTex[Random.Range(1,2)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
}
}
}