I have had this issue for a while and I can not find a solution to fix it. I manage to shoot bullets with trails. To do this, I create a bullet prefab and add a trail renderer to it. I shoot the bullet in another soldier game object by following steps:
Load the bullet prefab:
private void Awake()
{
bulletPrefab = Resources.Load<GameObject>("Enemy/Bullet");
Instantiate bullets from bullet prefab:
private void shoot(){
bullet = Instantiate(bulletPrefab);
bullet.transform.position = this.transform.position;
...
}
Then I update the bullet position according to the calculated angle and bullet speed. The problem is that when I shoot a bullet, the bullet will cast two trails, one trail going toward to the target which I set in the script and the other point to the bullet prefab I load in the Awake function. It seems that the bullet prefab loaded from resource folder does not show in the scene. However it affects the bullets which instantiated from it, making them point a trail to it.
How can I fix this issue?
I have resolved this issue by myself. The cause of this issue is actually pretty simple. I should choose
Instantiate(Object original, Vector3 position, Quaternion rotation)
rather thanInstantiate(Object original)
.The first version of instantiate creates the bullet in the given position; relocating the prefab after using the second version will render the unwanted trail.