campfire/Assets/Scripts/StartsInHand.cs

30 lines
952 B
C#
Raw Normal View History

2020-05-03 23:09:44 +02:00
using UnityEngine;
using Valve.VR.InteractionSystem;
using Valve.VR;
public class StartsInHand : MonoBehaviour {
public Hand Hand;
public Hand.AttachmentFlags Flags;
public bool StillInitiallyAttached = true;
public MonoBehaviour[] EnableOnDeattach;
private void Update() {
if (StillInitiallyAttached) {
GrabTypes GrabType = GrabTypes.Grip;
if (Hand.grabGripAction.state) {
2020-05-03 23:09:44 +02:00
StillInitiallyAttached = false;
GrabType = GrabTypes.Grip;
} else if (Hand.grabPinchAction.state) {
2020-05-03 23:09:44 +02:00
StillInitiallyAttached = false;
GrabType = GrabTypes.Pinch;
}
if (!StillInitiallyAttached) {
foreach (MonoBehaviour Component in EnableOnDeattach) {
Component.enabled = true;
}
}
Hand.AttachObject(gameObject, GrabType, Flags);
}
}
}