Spiel für das Medientheater HBK Saar, Teil des Projektes "Fun Palace" (Reupload der Repository von 2017)
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.

ViveLaserPointer.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ViveLaserPointer : MonoBehaviour {
  5. public static string sendMeToP5Bitch;
  6. public Transform controller;
  7. public enum AxisType
  8. {
  9. XAxis,
  10. ZAxis
  11. }
  12. public Color color;
  13. public float thickness = 0.002f;
  14. public AxisType facingAxis = AxisType.XAxis;
  15. public float length = 100f;
  16. public bool showCursor = true;
  17. GameObject holder;
  18. private GameObject hitPrimitive;
  19. // Use this for initialization
  20. void Start()
  21. {
  22. Material newMaterial = new Material(Shader.Find("Unlit/Color"));
  23. newMaterial.SetColor("_Color", color);
  24. holder = new GameObject();
  25. holder.transform.parent = controller.transform;
  26. holder.transform.localPosition = Vector3.zero;
  27. hitPrimitive = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  28. hitPrimitive.transform.localScale = new Vector3(0.2f,0.2f,0.2f);
  29. Destroy(hitPrimitive.GetComponent<Collider>());
  30. }
  31. void Update()
  32. {
  33. Ray raycast = new Ray(controller.transform.position, controller.transform.forward);
  34. Debug.DrawRay(raycast.origin, raycast.direction * 10000.0f, Color.red);
  35. RaycastHit hitObject;
  36. bool rayHit = Physics.Raycast(raycast, out hitObject);
  37. if (rayHit)
  38. {
  39. hitPrimitive.transform.position = hitObject.point;
  40. sendMeToP5Bitch = hitObject.point.ToString();
  41. }
  42. }
  43. }