campfire/Assets/Scripts/StartsInHand.cs

30 lines
982 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.Scripted;
if (SteamVR_Actions.default_GrabGrip.state) {
StillInitiallyAttached = false;
GrabType = GrabTypes.Grip;
} else if (SteamVR_Actions.default_GrabPinch.state) {
StillInitiallyAttached = false;
GrabType = GrabTypes.Pinch;
}
if (!StillInitiallyAttached) {
foreach (MonoBehaviour Component in EnableOnDeattach) {
Component.enabled = true;
}
}
Hand.AttachObject(gameObject, GrabType, Flags);
}
}
}