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

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;
        }


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值