12345678910111213141516171819202122232425262728293031323334353637383940 |
- using UnityEngine;
- /// <summary>
- /// </summary>
- public class TransformRotation : MonoBehaviour
- {
- public enum RotationType
- {
- One, Two, Three
- }
- public RotationType rotationType = RotationType.Three;
- private Transform cam;
- private Transform bb;
- [Range(0, 1)]
- public float alignYAxis = 1;
- public void Awake()
- {
- cam = Camera.main.transform;
- bb = this.transform;
- }
- public void Update()
- {
- if (rotationType == RotationType.One)
- {
- bb.LookAt(cam);
- }
- else if (rotationType == RotationType.Two)
- {
- bb.forward = (cam.position - bb.position).normalized;
- }
- else
- {
- bb.rotation = cam.transform.rotation;
- }
- var f = bb.forward;
- f.y *= alignYAxis;
- bb.forward = f;
- }
- }
|