I have this code for making each leaf on my tree look at the camera:
using UnityEngine;
public class Billboard : MonoBehaviour
{
private Transform m_transform;
private Transform m_camTransform;
private void Awake()
{
m_transform = transform;
m_camTransform = Camera.main.transform;
}
private void Update()
{
if (m_camTransform != null)
{
m_transform.LookAt(m_camTransform);
}
}
}
There is a difference of 70 FPS when this Update method is commented out. This script is on each leaf on my trees. Given the number of trees I have in scene, there are roughly 600 leaves in the scene with the script.
I have tried offloading this to a BillboardManager class:
using UnityEngine;
public class BillboardManager : MonoBehaviour
{
private Transform m_mainCamTransform;
private void Awake()
{
m_mainCamTransform = Camera.main.transform;
}
private void Update()
{
foreach(Billboard billboard in Billboard.m_billboards)
{
billboard.m_transform.LookAt(m_mainCamTransform);
}
}
}
But I only see 10 FPS difference in the 70 FPS loss...
↧