Vector2IntExtensions.cs 529 B

1234567891011121314151617
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public static class Vector2IntExtensions
  5. {
  6. public static Vector2Int Rotate(this Vector2Int v, float degrees)
  7. {
  8. float sin = Mathf.Sin(degrees * Mathf.Deg2Rad);
  9. float cos = Mathf.Cos(degrees * Mathf.Deg2Rad);
  10. float tx = v.x;
  11. float ty = v.y;
  12. float x = (cos * tx) - (sin * ty);
  13. float y = (sin * tx) + (cos * ty);
  14. return new Vector2Int(Mathf.RoundToInt(x), Mathf.RoundToInt(y));
  15. }
  16. }