30 lines
982 B
C#
30 lines
982 B
C#
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|