- Home /
Instantiated Bullet Hole not Rotated Properly
I have looked at questions similar to mine and none of the solutions seem to work in Unity 5.1.3f. Here is my whole C# Script for Instantiating the bullet hole along with a screenshot of the issue. Also, my bullet holes are not getting deleted from the first index in the list as I tried to do, but it seems to do nothing with the first index in the list.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BulletHole : MonoBehaviour {
public int maxDistance = 100;
public GameObject hitWall;
public float inFront = 0.001f;
private List<GameObject> list = new List<GameObject>();
void Update()
{
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.forward, out hit, maxDistance))
{
if(hit.transform.tag == "Level")
{
Instantiate(hitWall, hit.point, Quaternion.LookRotation(hit.normal));
list.Add(hitWall);
}
}
if (list.Count >= 20)
{
Destroy(list[0].gameObject);
}
}
}
Answer by Cherno · Oct 06, 2015 at 06:36 AM
I answered a question about the same problem here:
As for the list: The Destroy function only destroys the GameObject at index 0. You also need to remove that element from the list itself with List.RemoveAt().
Okay, awesome, I'll take a look at the previous answer you've posted, hopefully it works. $$anonymous$$y bad on the removing from list part, simple mistake on my part. I'll give the new code a go when I get home, thanks! @Cherno
Forgot to update you all, the thread you gave me was a savior, thanks!
Your answer
Follow this Question
Related Questions
Bullet hole on skinned mesh? 1 Answer
Bullet Holes, Decals 0 Answers
add material to object when a collision occurs 2 Answers
Bullet holes (decals?) on Characters 1 Answer
Bullet hole on target 3 Answers