隐藏鼠标,游戏截图,退出全屏

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class NewBehaviourScript : MonoBehaviour {
int a=0;
float timer=5;
void Start()
{
    Screen.sleepTimeout = 10;//在手机上有效 十秒无动作 屏幕变暗

}
void Update()
{
   //手动隐藏
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        Cursor . visible = !Cursor.visible;//隐藏鼠标
    }
HideCursor();
}
///<summary>
/// 进行截图 相同名字会被覆盖
///</summary>
public void CutScreem(){
    a++;
     Application.CaptureScreenshot("hujinbo"+a+".png");
}

/// <summary>
/// 鼠标5s内没有移动时 隐藏
/// <summary>
void HideCursor(){
     if (Input.GetAxis ("Mouse X")==0&&Input .GetAxis("Mouse Y")==0&&
!Input.GetMouseButton(0)&&!Input.GetMouseButton(1))
{ timer-=Time.deltaTime;
if (timer<=0)
{
     Cursor.visible=false;
     timer=5;
    
}
}else Cursor .visible=true;
}
    
    void OnGUI() {
         //全屏和窗口模式之间切换

Event e = Event.current;

if (e.clickCount==2){

Screen.fullScreen =!Screen .fullScreen;
    
        }


}

}

猜你喜欢

转载自blog.csdn.net/Hu_jinbo/article/details/80271169