-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpriteBillboard.cs
45 lines (36 loc) · 1.26 KB
/
SpriteBillboard.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using UnityEngine;
internal class SpriteBillboard : MonoBehaviour
{
[SerializeField] private BillboardType billboardType;
[Header("Lock Rotation")]
[SerializeField] private bool lockX;
[SerializeField] private bool lockY;
[SerializeField] private bool lockZ;
private static Vector3 originalRotation;
internal enum BillboardType { LookAtCamera, CameraForward };
private void Awake()
{
originalRotation = transform.rotation.eulerAngles;
}
private void LateUpdate()
{
switch (billboardType)
{
case BillboardType.LookAtCamera:
try { transform.LookAt(Camera.main.transform.position, Vector3.up); }
catch { break; }
break;
case BillboardType.CameraForward:
try { transform.forward = Camera.main.transform.forward; }
catch { break; }
break;
default:
break;
}
Vector3 rotation = transform.rotation.eulerAngles;
if (lockX) { rotation.x = originalRotation.x; }
if (lockY) { rotation.y = originalRotation.y; }
if (lockZ) { rotation.z = originalRotation.z; }
transform.rotation = Quaternion.Euler(rotation);
}
}