[Unity]什么是CrossPlatformInputManager.GetAxis()?
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/249
该问题为测试案例,不计入基本案例 。
Input.GetAxis和CrossPlatformInputManager.GetAxis的区别:
using UnityEngine;
using System.Collections;
using UnitySampleAssets.CrossPlatformInput;
public class CrossPlatformMoveSphere : MonoBehaviour
{
void Update ()
{
// 获取跨平台输入
var axis = CrossPlatformInputManager.GetAxis("Horizontal");
transform.position += Vector3.right * axis * Time.deltaTime;
}
}
using UnityEngine;
public class MoveSphere : MonoBehaviour
{
void Update ()
{
// 获取输入
var axis = Input.GetAxis("Horizontal");
transform.position += Vector3.right * axis * Time.deltaTime;
}
}
CrossPlatformInputManager和Input的区别:
基本上就是跨平台与不跨平台的区别。
在《Unity5权威讲解》中给出的SpaceShooter的基本案例中使用的是Input.GetAxis(),并没有详细介绍CrossPlatformInputManager.GetAxis()与之的区别。
但可以根据名称知道,CrossPlatform就是跨平台,
如果是PC版的默认还是Input,但是如果是在安卓、IOS等其他平台开发游戏的话,脚本中或许就必须用到CrossPlatformInputManager。
This article was last edited at 2020-04-11 10:04:35