BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Scripts / WorldGrab.cs

WorldGrab.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
WorldGrab.cs 1.1 KiB Download Raw
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5public class WorldGrab : MonoBehaviour
6{
7 [SerializeField] private Controllers type;
8 [SerializeField] private Transform handTransform;
9 [SerializeField] private Transform baseTransform;
10 public enum Controllers
11 {
12 Primary_Left, Secondary_Right
13 }
14
15 private bool grab = false;
16 private Vector3 handStart = Vector3.zero;
17 private Vector3 headStart = Vector3.zero;
18
19 // Update is called once per frame
20 void Update()
21 {
22 if(grab == false)
23 {
24 handStart = handTransform.localPosition;
25 headStart = baseTransform.position;
26 }
27
28 if (type == Controllers.Primary_Left)
29 {
30 grab = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) > 0.5f;
31 }
32
33 if (type == Controllers.Secondary_Right)
34 {
35 grab = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger) > 0.5f;
36 }
37
38 if (grab)
39 {
40 Vector3 delta = handTransform.localPosition - handStart;
41
42 baseTransform.position = headStart - delta;
43 }
44 }
45}