/
MirrorRotation.cs
36 lines (31 loc) · 926 Bytes
/
MirrorRotation.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MirrorRotation : MonoBehaviour
{
public enum MirrorType
{
ParentChild, ChildParent_Wrong, ParentInverse
}
[SerializeField]
GameObject parent, child;
[SerializeField]
MirrorType mirrorType;
protected void Update()
{
switch (mirrorType)
{
case MirrorType.ParentChild:
transform.localRotation = parent.transform.localRotation * (child == null ? Quaternion.identity : child.transform.localRotation);
break;
case MirrorType.ChildParent_Wrong:
transform.localRotation = (child == null ? Quaternion.identity : child.transform.localRotation) * parent.transform.rotation;
break;
case MirrorType.ParentInverse:
transform.localRotation = Quaternion.Inverse(parent.transform.rotation);
break;
default:
break;
}
}
}