Assignment for RMIT Mixed Reality in 2020
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.

41 lines
1.4 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class Sphere_Spawner : MonoBehaviour
  5. {
  6. private GameObject spawnMe;
  7. private Vector3 position;
  8. private void Start()
  9. {
  10. if (GetComponent<VRTK_ControllerEvents>() == null)
  11. {
  12. VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "Sphere_Spawner", "VRTK_ControllerEvents", "the same"));
  13. return;
  14. }
  15. GetComponent<VRTK_ControllerEvents>().TriggerPressed += new ControllerInteractionEventHandler(DoTriggerPressed);
  16. GetComponent<VRTK_ControllerEvents>().TouchpadPressed += new ControllerInteractionEventHandler(DoTouchpadPressed);
  17. spawnMe = GameObject.Find("SpawnMe");
  18. position = spawnMe.transform.position;
  19. }
  20. private void DoTriggerPressed(object sender, ControllerInteractionEventArgs e)
  21. {
  22. Invoke("CreateSphere", 0f);
  23. }
  24. private void DoTouchpadPressed(object sender, ControllerInteractionEventArgs e)
  25. {
  26. for (int i = 0; i < 20; i++)
  27. {
  28. Invoke("CreateSphere", 0f);
  29. }
  30. }
  31. private void CreateSphere()
  32. {
  33. Instantiate(spawnMe, position, Quaternion.identity);
  34. }
  35. }
  36. }