亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Unity實(shí)現(xiàn)人物旋轉(zhuǎn)和移動(dòng)效果

 更新時(shí)間:2020年01月20日 15:47:07   作者:StupidKen  
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)人物旋轉(zhuǎn)和移動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity實(shí)現(xiàn)人物旋轉(zhuǎn)和移動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下

旋轉(zhuǎn)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class MouseLook : MonoBehaviour {
 public enum RotationAxes
 {
 MouseXandY = 0,
 MouseX = 1,
 MouseY = 2
 }
 
 public RotationAxes axes = RotationAxes.MouseXandY;
 
 public float sensitivityHor = 9.0f;
 public float sensitivityVert = 9.0f;
 
 public float minVert = -45.0f;
 public float maxVert = 45.0f;
 
 private float _rotationX = 0;
 
 // Use this for initialization
 void Start () {
 Rigidbody body = GetComponent<Rigidbody> ();
 if (body != null) {
  body.freezeRotation = true;
 }
 }
 
 // Update is called once per frame
 void Update () {
 //水平旋轉(zhuǎn)就是以Y軸作為旋轉(zhuǎn)軸旋轉(zhuǎn),鼠標(biāo)移動(dòng)量為偏移量
 if (axes == RotationAxes.MouseX) {
  transform.Rotate (0, Input.GetAxis("Mouse X") * sensitivityHor, 0);//通過“增加”旋轉(zhuǎn)角度進(jìn)行旋轉(zhuǎn)(X,Y,Z為對(duì)應(yīng)方向的增加量),一般用于無限制旋轉(zhuǎn)
 } else if (axes == RotationAxes.MouseY) {
  _rotationX -= Input.GetAxis ("Mouse Y") * sensitivityVert;
  _rotationX = Mathf.Clamp (_rotationX, minVert, maxVert);//限制_rotationX的值在minVert與minVert之間
  float rotationY = transform.localEulerAngles.y;
  //Debug.Log ("rotationX:"+_rotationX+","+Input.GetAxis ("Mouse Y") * sensitivityVert);
  transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);//直接“設(shè)置”旋轉(zhuǎn)角度進(jìn)行旋轉(zhuǎn),一般用于有限制旋轉(zhuǎn)
 } else {
  _rotationX -= Input.GetAxis ("Mouse Y") * sensitivityVert;
  _rotationX = Mathf.Clamp (_rotationX, minVert, maxVert);
  float delta = Input.GetAxis ("Mouse X") * sensitivityHor;
  float rotationY = transform.localEulerAngles.y + delta;
  transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
 }
 }
}

移動(dòng)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
[RequireComponent(typeof(CharacterController))]//如果對(duì)象沒有該組件,則創(chuàng)建一個(gè)
[AddComponentMenu("Control Script/FPS Input")]//可以在Add Component查到
 
public class FPSInput : MonoBehaviour {
 
 private CharacterController _characterController;
 public float speed = 10.0f;
 public float gravity = -9.8f;
 // Use this for initialization
 void Start () {
 _characterController = GetComponent<CharacterController>();//獲取對(duì)象里的某一組件
 }
 
 // Update is called once per frame
 void Update () {
 float deltaX = Input.GetAxis ("Horizontal") * speed;
 float deltaZ = Input.GetAxis ("Vertical") * speed;
 Vector3 movement = new Vector3 (deltaX, 0, deltaZ);
 movement = Vector3.ClampMagnitude (movement, speed);//保持各方向的速度相同
 movement.y = gravity;
 movement = movement * Time.deltaTime;//向量可以直接乘以一個(gè)數(shù),Time.deltaTime確保在每臺(tái)計(jì)算機(jī)上的速度相同
 movement = transform.TransformDirection (movement);//將本地坐標(biāo)轉(zhuǎn)換為世界坐標(biāo)
 _characterController.Move(movement);//通過CharacterController進(jìn)行移動(dòng)而不是transform.Translate
 }
}

問題

人物移動(dòng)到父容器的邊緣時(shí),人物的移動(dòng)會(huì)產(chǎn)生偏移(甚至飛起來)。將父容器擴(kuò)大,使人物無法接近邊緣則不會(huì)有異常。

父容器比較大

父容器比較小,人物到達(dá)邊緣

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。 

相關(guān)文章

  • Unity擴(kuò)展Hierachry的右鍵菜單

    Unity擴(kuò)展Hierachry的右鍵菜單

    這篇文章主要為大家詳細(xì)介紹了Unity擴(kuò)展Hierachry的右鍵菜單,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • C#單向鏈表實(shí)現(xiàn)非升序插入方法的實(shí)例詳解

    C#單向鏈表實(shí)現(xiàn)非升序插入方法的實(shí)例詳解

    單向鏈表是一種數(shù)據(jù)結(jié)構(gòu),其中元素以線性方式連接在一起,每個(gè)元素都指向下一個(gè)元素,非升序插入意味著元素不是按升序(從小到大)插入鏈表中,本文給大家介紹了C#單向鏈表實(shí)現(xiàn)非升序插入方法的實(shí)例,需要的朋友可以參考下
    2024-03-03
  • C#?函數(shù)返回多個(gè)值的方法詳情

    C#?函數(shù)返回多個(gè)值的方法詳情

    這篇文章主要介紹了C#函數(shù)返回多個(gè)值的方法詳情,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09
  • 服務(wù)器端C#實(shí)現(xiàn)的CSS解析器

    服務(wù)器端C#實(shí)現(xiàn)的CSS解析器

    服務(wù)器端C#實(shí)現(xiàn)的CSS解析器
    2008-09-09
  • c#入門之類型轉(zhuǎn)換詳解

    c#入門之類型轉(zhuǎn)換詳解

    這篇文章主要介紹了c#的類型轉(zhuǎn)換詳解,類型轉(zhuǎn)換分兩種形式:隱式轉(zhuǎn)換、顯示轉(zhuǎn)換,下面是詳細(xì)介紹
    2014-04-04
  • C#從文件流讀取xml文件到DataSet并顯示的方法

    C#從文件流讀取xml文件到DataSet并顯示的方法

    這篇文章主要介紹了C#從文件流讀取xml文件到DataSet并顯示的方法,實(shí)例分析了C#操作XML文件的技巧與DataSet的使用方法,需要的朋友可以參考下
    2015-04-04
  • Unity UGUI控制text文字間距

    Unity UGUI控制text文字間距

    這篇文章主要為大家詳細(xì)介紹了Unity UGUI控制text文字間距的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • 淺析C#中文件路徑的操作

    淺析C#中文件路徑的操作

    在.NET類庫(kù)中,有一個(gè)專門的功能類System.IO.Path,對(duì)表示文件或在目錄路徑的string進(jìn)行操作。本文介紹下利用Path來對(duì)文件路徑進(jìn)行的一些經(jīng)常用操作。感興趣的朋友可以看下
    2016-12-12
  • C#讀取目錄下所有指定類型文件的方法

    C#讀取目錄下所有指定類型文件的方法

    這篇文章主要介紹了C#讀取目錄下所有指定類型文件的方法,可實(shí)現(xiàn)讀取目錄下特定后綴名文件的功能,需要的朋友可以參考下
    2015-06-06
  • 分享WCF文件傳輸實(shí)現(xiàn)方法---WCFFileTransfer

    分享WCF文件傳輸實(shí)現(xiàn)方法---WCFFileTransfer

    這篇文章主要介紹了分享WCF文件傳輸實(shí)現(xiàn)方法---WCFFileTransfer,需要的朋友可以參考下
    2015-11-11

最新評(píng)論