2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

5 years ago
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Spawns and attaches an object to the hand after the controller has
  4. // tracking
  5. //
  6. //=============================================================================
  7. using UnityEngine;
  8. using System.Collections;
  9. namespace Valve.VR.InteractionSystem
  10. {
  11. //-------------------------------------------------------------------------
  12. public class SpawnAndAttachAfterControllerIsTracking : MonoBehaviour
  13. {
  14. private Hand hand;
  15. public GameObject itemPrefab;
  16. //-------------------------------------------------
  17. void Start()
  18. {
  19. hand = GetComponentInParent<Hand>();
  20. }
  21. //-------------------------------------------------
  22. void Update()
  23. {
  24. if ( itemPrefab != null )
  25. {
  26. if (hand.isActive && hand.isPoseValid)
  27. {
  28. GameObject objectToAttach = GameObject.Instantiate(itemPrefab);
  29. objectToAttach.SetActive(true);
  30. hand.AttachObject(objectToAttach, GrabTypes.Scripted);
  31. hand.TriggerHapticPulse(800);
  32. Destroy(gameObject);
  33. // If the player's scale has been changed the object to attach will be the wrong size.
  34. // To fix this we change the object's scale back to its original, pre-attach scale.
  35. objectToAttach.transform.localScale = itemPrefab.transform.localScale;
  36. }
  37. }
  38. }
  39. }
  40. }