ActionPoint.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. namespace TrackpointApp
  3. {
  4. public class ActionPoint : MonoBehaviour
  5. {
  6. private GameObject cylinder;
  7. private const int divisor = Configuration.divisor;
  8. public void setup()
  9. {
  10. cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
  11. cylinder.transform.parent = gameObject.transform;
  12. cylinder.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
  13. cylinder.transform.localRotation = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f);
  14. cylinder.GetComponent<Renderer>().material.color = Color.blue;
  15. size(2.5f / divisor, 2.0f / divisor);
  16. }
  17. private void size(float radius, float length)
  18. {
  19. float actualLength = cylinder.GetComponent<Renderer>().bounds.size.y;
  20. float actualDiameter = cylinder.GetComponent<Renderer>().bounds.size.x;
  21. Vector3 rescale = cylinder.transform.localScale;
  22. rescale.y = length * rescale.y / actualLength;
  23. float xzFactor = radius * 2 * rescale.x / actualDiameter;
  24. rescale.x = xzFactor;
  25. rescale.z = xzFactor;
  26. cylinder.transform.localScale = rescale;
  27. }
  28. }
  29. }