| 123456789101112131415161718192021222324252627282930 |
- using UnityEngine;
- using System.Collections;
- public class LookAtTarget : MonoBehaviour
- {
- public Transform target;
- // Use this for initialization
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (target == null) return;
-
- this.transform.rotation = GetLookRotation();
- }
- Quaternion GetLookRotation()
- {
- Vector3 lookDir = target.position - transform.position;
- return Quaternion.LookRotation(lookDir, Vector3.up);
- }
- }
|