欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

Unity3D實現(xiàn)控制攝像機移動

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

本文實例為大家分享了Unity3D實現(xiàn)控制攝像機移動的具體代碼,供大家參考,具體內(nèi)容如下

最近公司的幾個項目開發(fā)內(nèi)容基本相同,很多腳本直接復(fù)制過來就可以拼接項目。之前一直是代碼愛好者,能自己敲的絕對不去復(fù)制粘貼。但是開發(fā)速度確實是被耽誤了,所以接下來打算把開發(fā)中常用的腳本都發(fā)到博客上。自己需要的時候直接拿來。也希望能幫到你們。

unity編輯器中按住鼠標(biāo)右鍵,在通過控制鍵盤的wasdqe鍵可以自由控制視野。

下面就是實現(xiàn)操作的代碼:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
//巡游模式攝像機控制
public class CameraMove : MonoBehaviour
{
 
  public static CameraMove Instance = null;
  
  private Vector3 dirVector3;
  private Vector3 rotaVector3;
  private float paramater = 0.1f;
  //旋轉(zhuǎn)參數(shù)
  private float xspeed = -0.05f;
  private float yspeed = 0.1f;
 
 private float dis;
 
  void Awake ()
 {
   Instance = this;
 }
 
  private void Start()
  {
    rotaVector3 = transform.localEulerAngles;
 dis = UIFuc.Instance.Dis;
  }
 
  // Update is called once per frame
 void FixedUpdate ()
  {
    //旋轉(zhuǎn)
    if (Input.GetMouseButton(1))
    {
      rotaVector3.y += Input.GetAxis("Horizontal") * yspeed;
      rotaVector3.x += Input.GetAxis("Vertical") * xspeed;
      transform.rotation = Quaternion.Euler(rotaVector3);
    }
 
    //移動
    dirVector3 =Vector3.zero;
 
    if (Input.GetKey(KeyCode.W))
    {
      if(Input.GetKey(KeyCode.LeftShift)) dirVector3.z = 3;
      else dirVector3.z = 1;
    }
    if (Input.GetKey(KeyCode.S))
    {
      if (Input.GetKey(KeyCode.LeftShift)) dirVector3.z = -3;
      else dirVector3.z = -1;
    }
    if (Input.GetKey(KeyCode.A))
    {
      if (Input.GetKey(KeyCode.LeftShift)) dirVector3.x = -3;
      else dirVector3.x = -1;
    }
    if (Input.GetKey(KeyCode.D))
    {
      if (Input.GetKey(KeyCode.LeftShift)) dirVector3.x = 3;
      else dirVector3.x = 1;
    }
    if (Input.GetKey(KeyCode.Q))
    {
      if (Input.GetKey(KeyCode.LeftShift)) dirVector3.y = -3;
      else dirVector3.y = -1;
    }
    if (Input.GetKey(KeyCode.E))
    {
      if (Input.GetKey(KeyCode.LeftShift)) dirVector3.y = 3;
      else dirVector3.y = 1;
    }
    transform.Translate(dirVector3 * paramater,Space.Self);
    //限制攝像機范圍
 transform.position = Vector3.ClampMagnitude(transform.position, dis);
  }
}

由于項目需要限制攝像機的移動范圍,所以我在最后加上了限制的代碼。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:Unity控制指針旋轉(zhuǎn)到指定位置

欄    目:C#教程

下一篇:C#基于HttpWebRequest實現(xiàn)發(fā)送HTTP請求的方法分析

本文標(biāo)題:Unity3D實現(xiàn)控制攝像機移動

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/4913.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有