private void FixedUpdate() { this.m_Rigidbody.velocity = transform.forward * m_Speed; if (!this.m_FollowTarget) { return; } if (this.m_Target != null) { Vector3 targetPosition = UnityTools.GetBounds(this.m_Target.gameObject).center; if (this.m_TurnSpeed < 0f) { transform.LookAt(targetPosition); } else { Vector3 directionToTarget = targetPosition - transform.position; Vector3 currentDirection = transform.forward; Vector3 resultingDirection = Vector3.RotateTowards(currentDirection, directionToTarget, this.m_TurnSpeed * Mathf.Deg2Rad * Time.fixedDeltaTime, 1f); transform.rotation = Quaternion.LookRotation(resultingDirection); } } }
private void LateUpdate() { Vector3 pos = UnityTools.GetBounds(this.m_Target.gameObject).center + this.m_Offset; Vector3 screenPos = Camera.main.WorldToScreenPoint(pos); this.m_Text.enabled = screenPos.x > 0 && screenPos.x < Camera.main.pixelWidth && screenPos.y > 0 && screenPos.y < Camera.main.pixelHeight && screenPos.z > 0; transform.position = Camera.main.WorldToScreenPoint(UnityTools.GetBounds(this.m_Target.gameObject).center + this.m_Offset); }