赞
踩
详细的资料可以看这个大佬总结的:参考资料
我这里直接用图结合着说:
下面是测试代码:
- using UnityEngine;
-
- /// <summary>
- ///
- /// * Writer:June
- /// *
- /// * Data:2021.4.2
- /// *
- /// * Function:区别LookAt与LookRotation
- /// *
- /// * Remarks:
- ///
- /// </summary>
-
- public class LookTest : MonoBehaviour
- {
- /// <summary>
- /// 敌人
- /// </summary>
- public Transform target;
-
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.A))
- {
- transform.LookAt(target);
- }
- if (Input.GetKeyDown(KeyCode.S))
- {
- transform.rotation = Quaternion.LookRotation(target.position);
- }
- if (Input.GetKeyDown(KeyCode.D))
- {
- transform.rotation = Quaternion.LookRotation(target.position - transform.position);
- }
- //画原点与敌人之间的线
- Debug.DrawLine(Vector3.zero, target.position, Color.yellow);
- //画主角与敌人之间的线
- Debug.DrawLine(transform.position, target.position, Color.black);
-
- }
- }
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。