使用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资源,都会陆续发放)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐