private Vector2 GenerateRelictVelocity() { Vector2 normal = Vector2Helpers.DegreeToVector2(RandomHelpers.Range(relicAngle)); float velocity = TileHelpers.TileToWorld(RandomHelpers.Range(relicTileVelocity)); return(normal * velocity); }
public void OnDeath(PlayerUnitController unit, Vector2 relictVelocity) { PlayerBaseStats stats = unit.di.stats; SlimeType poofType = stats.SlimeType; Vector2 spawnPosition = unit.transform.position; SlimePoof slimePoof = poofs[poofType]; slimePoof.SpawnAt(spawnPosition); foreach (SlimeType type in SlimeTypeHelpers.GetEnumerable()) { if (stats.HasType(type)) { SlimeRelict relict = relicts[type]; relict.SpawnAt(spawnPosition); Vector2 velocity = GenerateRelictVelocity(); relict.SetVelocity(velocity); relict.SetRotation(RandomHelpers.Range(relicRotationsPerSecond)); //relictVelocity = Vector2.zero; } } }
public static T GetRandomElement <T>(this T src) where T : struct { if (!typeof(T).IsEnum) { throw new ArgumentException(String.Format("Argument {0} is not an Enum", typeof(T).FullName)); } T[] Arr = (T[])Enum.GetValues(src.GetType()); return(Arr[RandomHelpers.Range(Arr.Length)]); }
public static void Shuffle <T>(this IList <T> list) { int n = list.Count; while (n > 1) { n--; int k = RandomHelpers.Range(n + 1); T value = list[k]; list[k] = list[n]; list[n] = value; } }
public static TValue GetRandomValue <TKey, TValue>(this IDictionary <TKey, TValue> self) { return(self.ElementAt(RandomHelpers.Range(self.Count)).Value); }
public static T GetRandomValue <T>(this IList <T> list) { return(list[RandomHelpers.Range(list.Count)]); }