使用unity制作游戏时,有时候需要在游戏中触发手机的物理返回键和home键,下面在update方法中每帧监听是否按下了该键,然后写入自己要调用的方法
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Physics_exit : MonoBehaviour
{ /// <summary>
/// 每帧刷新
/// </summary>
void Update()
{
if (Application.platform == RuntimePlatform.Android && Input.GetKeyDown(KeyCode.Escape)) // 返回键
{
}
if (Application.platform == RuntimePlatform.Android && Input.GetKeyDown(KeyCode.Home)) // Home键
{
}
}
}
喂馨宫众浩:GameResources,海量免费资源任意下载(包括,unity资源,游戏工程代码,ui资源,都会陆续发放)