EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

OR

[Unity]什么是CrossPlatformInputManager.GetAxis()?

该问题为测试案例,不计入基本案例 。

 

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 19:04:35

* *