1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using UnityEngine;
- using System.Collections;
- namespace YLBattle
- {
- public class LookAtTarget : MonoBehaviour
- {
- public int level = 0;
- Transform target;
- public float speed = 20f;
- Transform mTrans;
- void Start()
- {
- mTrans = transform;
- }
- void LateUpdate()
- {
- if (target == null)
- {
- if (Camera.main != null)
- {
- target = CameraManager.Instance.SenceCamara.transform;
- }
- }
- if (target != null)
- {
- Vector3 dir = target.position - mTrans.position;
- float mag = dir.magnitude;
- if (mag > 0.001f)
- {
- Quaternion lookRot = Quaternion.LookRotation(dir);
- mTrans.rotation = Quaternion.Slerp(mTrans.rotation, lookRot, Mathf.Clamp01(speed * Time.deltaTime));
- }
- }
- }
- }
- }
|