blob: d24caf20373f3c68726ae7f123a0c0f559499d1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
using UnityEngine;
namespace Rewired.Demos;
[AddComponentMenu("")]
public class CustomControllersTiltDemo : MonoBehaviour
{
public Transform target;
public float speed = 10f;
private CustomController controller;
private Player player;
private void Awake()
{
Screen.orientation = ScreenOrientation.LandscapeLeft;
player = ReInput.players.GetPlayer(0);
ReInput.InputSourceUpdateEvent += OnInputUpdate;
controller = (CustomController)player.controllers.GetControllerWithTag(ControllerType.Custom, "TiltController");
}
private void Update()
{
if (!(target == null))
{
Vector3 zero = Vector3.zero;
zero.y = player.GetAxis("Tilt Vertical");
zero.x = player.GetAxis("Tilt Horizontal");
if (zero.sqrMagnitude > 1f)
{
zero.Normalize();
}
zero *= Time.deltaTime;
target.Translate(zero * speed);
}
}
private void OnInputUpdate()
{
Vector3 acceleration = Input.acceleration;
controller.SetAxisValue(0, acceleration.x);
controller.SetAxisValue(1, acceleration.y);
controller.SetAxisValue(2, acceleration.z);
}
}
|