-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPickup.cs
63 lines (58 loc) · 2.03 KB
/
Pickup.cs
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
61
62
63
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Valve.VR;
public class Pickup : MonoBehaviour
{
SteamVR_Controller.Device device;
SteamVR_TrackedObject trackedObject;
public bool pickedUp;
FixedJoint fixJoint;
Rigidbody rigid;
void Start()
{
trackedObject = GetComponentInParent<SteamVR_TrackedObject>();
device = SteamVR_Controller.Input((int)trackedObject.index);
rigid = GetComponent<Rigidbody>();
}
void OnTriggerStay(Collider col)
{
if (col.CompareTag("pickup") && device.GetPressDown(SteamVR_Controller.ButtonMask.Grip) &&
col.transform.parent == null)
{
col.attachedRigidbody.isKinematic = true;
col.attachedRigidbody.useGravity = false;
col.transform.parent = this.transform;
pickedUp = true;
}
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Grip) && col.transform.parent != null)
{
col.attachedRigidbody.isKinematic = false;
col.attachedRigidbody.useGravity = true;
col.attachedRigidbody.velocity = device.velocity;
col.attachedRigidbody.angularVelocity = device.angularVelocity;
col.transform.parent = null;
pickedUp = false;
}
}
/*
void OnTriggerStay(Collider col)
{
if (col.CompareTag("pickup") && device.GetPressDown(SteamVR_Controller.ButtonMask.Grip) &&
fixJoint == null)
{
fixJoint = col.gameObject.AddComponent<FixedJoint>();
fixJoint.connectedBody = rigid;
pickedUp = true;
}
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Grip) && fixJoint != null)
{
Destroy(fixJoint);
col.attachedRigidbody.velocity = device.velocity;
col.attachedRigidbody.angularVelocity = device.angularVelocity;
pickedUp = false;
}
}
*/
}