holopy3/Assets/SteamVR/InteractionSystem/Core/Scripts/SpawnAndAttachToHand.cs

38 lines
889 B
C#
Raw Permalink Normal View History

2020-12-10 14:25:12 +00:00
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
//
// Purpose: Creates an object and attaches it to the hand
//
//=============================================================================
using UnityEngine;
using System.Collections;
namespace Valve.VR.InteractionSystem
{
//-------------------------------------------------------------------------
public class SpawnAndAttachToHand : MonoBehaviour
{
public Hand hand;
public GameObject prefab;
//-------------------------------------------------
public void SpawnAndAttach( Hand passedInhand )
{
Hand handToUse = passedInhand;
if ( passedInhand == null )
{
handToUse = hand;
}
if ( handToUse == null )
{
return;
}
GameObject prefabObject = Instantiate( prefab ) as GameObject;
handToUse.AttachObject( prefabObject, GrabTypes.Scripted );
}
}
}