bullet holes parenting
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));
}
}
}
Answer by Happy-Zomby · Mar 25, 2016 at 06:12 PM
Hi, you can parent it to the hit object by doing something like this:
if(Input.GetButton ("Fire1") && Physics.Raycast(transform.position, fwd, hit, 100))
{
var tempBullet : Instantiate(bulletTex[Random.Range(1,2)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
tempBullet.transform.parent = hit.transform;
}
Hope that helps,
Assets/BulletHoles.js(49,41): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/BulletHoles.js(49,70): BCE0044: expecting ), found ','.
Assets/BulletHoles.js(49,71): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/BulletHoles.js(49,81): BCE0043: Unexpected token: ,.
Assets/BulletHoles.js(49,82): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/BulletHoles.js(49,132): BCE0043: Unexpected token: ).
thanks but it doesnt work, now i cant see the bullet holes at all..
@Happy-Zomby Oh You just Did it, Thanks a lot to you. It Works fine for me. You are awesome