当前位置:   article > 正文

Unity3D c# 使对象物体始终面向摄像机。_3d ui跟随摄像机旋转,始终面向摄像机 unity

3d ui跟随摄像机旋转,始终面向摄像机 unity
Unity3D c# 使对象物体始终面向摄像机。


  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class LookAtMainCamera : MonoBehaviour {
  5. // Use this for initialization
  6. void Start () {
  7. }
  8. // Update is called once per frame
  9. void Update () {
  10. //当前对象始终面向摄像机。
  11. this.transform.LookAt(Camera.main.transform.position);
  12. this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(Camera.main.transform.position - this.transform.position),0);
  13. }
  14. }




using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class LookAtMainCamera : MonoBehaviour {


// Use this for initialization
void Start () {

}
// Update is called once per frame
void Update () {
        //当前对象始终面向摄像机。
        this.transform.LookAt(Camera.main.transform.position);
        this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(Camera.main.transform.position - this.transform.position),0);
    }
}
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/108850
推荐阅读
相关标签
  

闽ICP备14008679号