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.

53 lines
1.5 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class Menu_Object_Spawner : VRTK_InteractableObject
  5. {
  6. public enum PrimitiveTypes
  7. {
  8. Cube,
  9. Sphere
  10. }
  11. public PrimitiveTypes shape;
  12. private Color selectedColor;
  13. public void SetSelectedColor(Color color)
  14. {
  15. selectedColor = color;
  16. gameObject.GetComponent<MeshRenderer>().material.color = color;
  17. }
  18. public override void StartUsing(VRTK_InteractUse usingObject)
  19. {
  20. base.StartUsing(usingObject);
  21. if (shape == PrimitiveTypes.Cube)
  22. {
  23. CreateShape(PrimitiveType.Cube, selectedColor);
  24. }
  25. else if (shape == PrimitiveTypes.Sphere)
  26. {
  27. CreateShape(PrimitiveType.Sphere, selectedColor);
  28. }
  29. ResetMenuItems();
  30. }
  31. private void CreateShape(PrimitiveType shape, Color color)
  32. {
  33. GameObject obj = GameObject.CreatePrimitive(shape);
  34. obj.transform.position = transform.position;
  35. obj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
  36. obj.GetComponent<MeshRenderer>().material.color = color;
  37. obj.AddComponent<Rigidbody>();
  38. }
  39. private void ResetMenuItems()
  40. {
  41. foreach (Menu_Object_Spawner menuObjectSpawner in FindObjectsOfType<Menu_Object_Spawner>())
  42. {
  43. menuObjectSpawner.StopUsing();
  44. }
  45. }
  46. }
  47. }