-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensionMethods.cs
More file actions
31 lines (27 loc) · 836 Bytes
/
ExtensionMethods.cs
File metadata and controls
31 lines (27 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Collections.Generic;
using UnityEngine;
public static class ExtensionMethods {
public static Vector3 ToIsoVec3(this Vector2 input) {
var vec3 = new Vector3(input.x, 0f, input.y).normalized;
var quat = Quaternion.Euler(0f, 45f, 0f);
var rotated = quat * vec3;
return rotated;
}
public static void FaceCamera(this Transform t) {
t.forward = Camera.main.transform.forward;
}
/// <summary>
/// Get a random Element from the list.
/// </summary>
public static T Random<T>(this List<T> list) {
return list[UnityEngine.Random.Range(0, list.Count)];
}
/// <summary>
/// Get a random Element from the list AND remove it from the list.
/// </summary>
public static T RemoveRandom<T>(this List<T> list) {
var item = list[UnityEngine.Random.Range(0, list.Count)];
list.Remove(item);
return item;
}
}