JoeJeffController.cs
1.75 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEngine;
using System.Collections;
using Valve.VR;
using Valve.VR.InteractionSystem;
namespace Valve.VR.InteractionSystem.Sample
{
public class JoeJeffController : MonoBehaviour
{
public Transform Joystick;
public float joyMove = 0.1f;
public SteamVR_Action_Vector2 moveAction = SteamVR_Input.GetAction<SteamVR_Action_Vector2>("platformer", "Move");
public SteamVR_Action_Boolean jumpAction = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("platformer", "Jump");
public JoeJeff character;
public Renderer jumpHighlight;
private Vector3 movement;
private bool jump;
private float glow;
private SteamVR_Input_Sources hand;
private Interactable interactable;
private void Start()
{
interactable = GetComponent<Interactable>();
}
private void Update()
{
if (interactable.attachedToHand)
{
hand = interactable.attachedToHand.handType;
Vector2 m = moveAction[hand].axis;
movement = new Vector3(m.x, 0, m.y);
jump = jumpAction[hand].stateDown;
glow = Mathf.Lerp(glow, jumpAction[hand].state ? 1.5f : 1.0f, Time.deltaTime * 20);
}
else
{
movement = Vector2.zero;
jump = false;
glow = 0;
}
Joystick.localPosition = movement * joyMove;
float rot = transform.eulerAngles.y;
movement = Quaternion.AngleAxis(rot, Vector3.up) * movement;
jumpHighlight.sharedMaterial.SetColor("_EmissionColor", Color.white * glow);
character.Move(movement * 2, jump);
}
}
}