码迷,mamicode.com
首页 > 编程语言 > 详细

unity 2d 版的lookAt

时间:2019-08-06 14:01:52      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:span   nbsp   target   unit   tar   col   oat   tor   orm   

    void LookAt2D(Transform target)
    {
        Vector3 dir = target.position - transform.position;
        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }

 以X轴指向的方向

unity 2d 版的lookAt

标签:span   nbsp   target   unit   tar   col   oat   tor   orm   

原文地址:https://www.cnblogs.com/sanyejun/p/11308332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!