When a lot is happening in my game some frame dont run this simple script

Greetings,

I have a game in which the player runs through dungeons. All monsters and the player as well as many elements in game that are 2d and are rendered at an angle that faces the camera. The camera looks down at the world at a 45% degree angle (isometric like) so I can make a mix of 2d and 3d elements.

At times when a lot is happening the script that controls this is ignored and everything, never individual things are all rendered at a 0% degree angle making them look like they are lying down.

It only happens when there is a lot on the screen or when I have been working for a long time. perhaps something to do with memory or something?

the script is as follows:

    public class FaceCamera : MonoBehaviour {

    public Transform target;

    void Start()
    {
        target = GameObject.Find("MainCamera").GetComponent<Transform>();
    }

    void Update()
    {

        if (target != null)
        {
            this.transform.rotation = Camera.main.transform.rotation;
        }
    }
}

Does anyone have a suggestion of what this could be and where I can look further to solve this issue?

What is the point of the “target” variable? You don’t use it beside the null check. did you mean to do:

target.rotation = Camera.main.transform.rotation;

Currently your script does rotate the object this script is attached to. Though if that’s the purpose, what is that target good for?