滑鼠在螢幕上的移動來控制相機水平,垂直旋轉

來源:互聯網
上載者:User

標籤:pre   engine   ace   lamp   lam   nbsp   oid   bsp   layer   

using UnityEngine;using System.Collections;public class CameraController : MonoBehaviour {    public float distance_v;    public float distance_h;    public float rotation_H_speed=1;    public float rotation_V_speed=1;    public float max_up_angle = 80;              //越大,頭抬得越高    public float max_down_angle =-60;            //越小,頭抬得越低    public Transform follow_obj;        //player    private float current_rotation_H;      //水平旋轉結果    private float current_rotation_V;  //垂直旋轉結果    void LateUpdate()          {        //控制旋轉        current_rotation_H+= Input.GetAxis("Mouse X")*rotation_H_speed;        current_rotation_V += Input.GetAxis("Mouse Y")*rotation_V_speed;        current_rotation_V=Mathf.Clamp(current_rotation_V, max_down_angle, max_up_angle);       //限制垂直旋轉角度        transform.localEulerAngles = new Vector3(-current_rotation_V,current_rotation_H,0f);                //改變位置,以跟蹤的目標為視野中心,且視野中心總是面向follow_obj        transform.position =follow_obj.position;        transform.Translate(Vector3.back * distance_h, Space.Self);        transform.Translate(Vector3.up * distance_v, Space.World);          //相對於全局座標y軸向上    }}

 

滑鼠在螢幕上的移動來控制相機水平,垂直旋轉

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.