设置相机灵敏度和视距平滑

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
using UnityEngine.UI;

public class Tiao_jie : MonoBehaviour {
    public Text textdemo;
    public Text textdemo2;
    //灵敏度
    private float lingmin=2;
    
    private bool smooth_demo;
	// Use this for initialization
	void Start () {
        
       
    }
	
	// Update is called once per frame
	void Update () {
        
        
        

        if (Input.GetKeyDown(KeyCode.KeypadMinus))
        {
            lingmin -= 0.2f;
            
            if (lingmin <0)
            {
                lingmin = 0.2f;
            }

          
            transform.GetComponent<FirstPersonController>().m_MouseLook.XSensitivity = lingmin;
            transform.GetComponent<FirstPersonController>().m_MouseLook.YSensitivity = lingmin;

            StartCoroutine(Ynahi());
        }
        if (Input.GetKeyDown(KeyCode.KeypadPlus))
        {
            lingmin += 0.2f;
            
            if (lingmin > 2)
            {
                lingmin = 2;
            }

            transform.GetComponent<FirstPersonController>().m_MouseLook.XSensitivity = lingmin;
            transform.GetComponent<FirstPersonController>().m_MouseLook.YSensitivity = lingmin;
            StartCoroutine(Ynahi());
        }
        if (Input.GetMouseButtonDown(2))
        {
            if (smooth_demo == false)
            {
                transform.GetComponent<FirstPersonController>().m_MouseLook.smooth = false;
            }
            else
            {
                transform.GetComponent<FirstPersonController>().m_MouseLook.smooth = true;
            }
            smooth_demo = !smooth_demo;
            print(transform.GetComponent<FirstPersonController>().m_MouseLook.smooth);
            StartCoroutine(Ynahi());
        }
        textdemo.text=string.Format("灵敏度:{0}", lingmin);
        textdemo2.text = string.Format("是否平滑:{0}", transform.GetComponent<FirstPersonController>().m_MouseLook.smooth);
    }
    IEnumerator Ynahi()
    {
        textdemo.gameObject.SetActive(true);
        textdemo2.gameObject.SetActive(true);
        yield return new WaitForSeconds(3);
        textdemo.gameObject.SetActive(false);
        textdemo2.gameObject.SetActive(false);
    }
  
}
       //调节视距
        Camera.main.fieldOfView = Camera.main.fieldOfView -Input.GetAxis("Mouse ScrollWheel") * 20;
        Camera.main.fieldOfView = Mathf.Clamp(Camera.main.fieldOfView, 10, 60);
        if (Input.GetKeyDown(KeyCode.F1))
        {
            Camera.main.fieldOfView = fileviewdefault;
            transform.GetComponent<MouseLook>().XSensitivity = 2;
            transform.GetComponent<MouseLook>().YSensitivity = 2;
            transform.GetComponent<MouseLook>().smoothTime = 20;
        }


猜你喜欢

转载自blog.csdn.net/fanfan_hongyun/article/details/80968301