Whenever I attach this script to my game object and I start the game the sprite turns invisible. Everything else seems fine.
public class FollowPlayerBullet : MonoBehaviour {
public float speed;
private Transform lookAtTarget;
void Start()
{
GameObject tar = GameObject.FindGameObjectWithTag("Player");
if (tar)
{
lookAtTarget = tar.transform;
}
}
void FixedUpdate()
{
transform.LookAt(lookAtTarget);
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
}

It is not the destroy bullet script as it is the same without that script. I tried changing up the sorting layers and that didn’t work. The only thing that seems to be causing the sprite to disappear is that script. Also any improvements on the script itself would help too, it should be a bullet that is instantiated and follows the player for five seconds. Thank You
I tried the script with the same components and the sprite remains visible to me. However, since you are using the lookat method, most likely the sprite gets oriented orthogonal to the camera and becomes invisible.
I modified the script slightly and got this result.
here is the modified method.
Vector3 direction = lookAtTarget.position - transform.position;
Quaternion toRotation = Quaternion.FromToRotation(transform.right, direction);
//transform.LookAt(lookAtTarget,Vector3.right);
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, rotateSpeed * Time.time);
transform.Translate(Vector3.right * speed * Time.deltaTime);
Hope this helps !
@hapynoid continuing my comment. You can solve this problem by following methods
-
changing the rotation of sprite at
runtime (so it won’t affect your
project atm) and check when it is
visible and note down the rotation
values. Afterwards, stop the game
and add the following line to your
script right after transform.LookAt(lookAtTarget);
transform.rotation = transform.localEulerAngles = new Vector3(x,y,z);
where x,y and z will be angles you noted down at runtime.
This is not the desired way, because it would make your lookAt function render useless, as you’ll need to change the rotation, making it face a different way.
- You should set all your gameObjects in x-y axis (in 2D), so their’s no rotation in z axis. That would make the lookAt function better, because you won’t have any z-rotation and your sprite will be visible.