31 [Tooltip(
"Specifies the axis about which the object will rotate.")]
36 get {
return pivotAxis; }
37 set { pivotAxis = value; }
43 [Tooltip(
"Specifies the target we will orient to. If no target is specified, the main camera will be used.")]
45 private Transform targetTransform;
46 public Transform TargetTransform
48 get {
return targetTransform; }
49 set { targetTransform = value; }
52 private void OnEnable()
54 if (TargetTransform == null)
66 private void LateUpdate()
68 if (TargetTransform == null)
81 Vector3 directionToTarget = TargetTransform.position - transform.position;
83 bool useCameraAsUpVector =
true;
89 directionToTarget.x = 0.0f;
90 useCameraAsUpVector =
false;
94 directionToTarget.y = 0.0f;
95 useCameraAsUpVector =
false;
99 directionToTarget.x = 0.0f;
100 directionToTarget.y = 0.0f;
104 useCameraAsUpVector =
false;
108 directionToTarget.x = 0.0f;
112 directionToTarget.y = 0.0f;
122 if (directionToTarget.sqrMagnitude < 0.001f)
128 if (useCameraAsUpVector)
130 transform.rotation = Quaternion.LookRotation(-directionToTarget,
CameraCache.
Main.transform.up);
134 transform.rotation = Quaternion.LookRotation(-directionToTarget);