Brak opisu
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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.U2D;
  5. namespace SpriteShapeExtras
  6. {
  7. public class Sprinkler : MonoBehaviour
  8. {
  9. public GameObject m_Prefab;
  10. public float m_RandomFactor = 10.0f;
  11. public bool m_UseNormals = false;
  12. float Angle(Vector3 a, Vector3 b)
  13. {
  14. float dot = Vector3.Dot(a, b);
  15. float det = (a.x * b.y) - (b.x * a.y);
  16. return Mathf.Atan2(det, dot) * Mathf.Rad2Deg;
  17. }
  18. // Use this for initialization. Plant the Prefabs on Startup
  19. void Start ()
  20. {
  21. SpriteShapeController ssc = GetComponent<SpriteShapeController>();
  22. Spline spl = ssc.spline;
  23. for (int i = 1; i < spl.GetPointCount() - 1; ++i)
  24. {
  25. if (Random.Range(0, 100) > (100 - m_RandomFactor) )
  26. {
  27. var go = GameObject.Instantiate(m_Prefab);
  28. go.transform.position = spl.GetPosition(i);
  29. if (m_UseNormals)
  30. {
  31. Vector3 lt = Vector3.Normalize(spl.GetPosition(i - 1) - spl.GetPosition(i));
  32. Vector3 rt = Vector3.Normalize(spl.GetPosition(i + 1) - spl.GetPosition(i));
  33. float a = Angle(Vector3.up, lt);
  34. float b = Angle(lt, rt);
  35. float c = a + (b * 0.5f);
  36. if (b > 0)
  37. c = (180 + c);
  38. go.transform.rotation = Quaternion.Euler(0, 0, c);
  39. }
  40. }
  41. }
  42. }
  43. // Update is called once per frame
  44. void Update ()
  45. {
  46. }
  47. }
  48. }