static GameObject[] SpawnFlingsInternal(FlingInfo info, Vector3 spawnPoint, CardinalDirection direction) { float angleMin = info.AngleMin; float angleMax = info.AngleMax; AdjustAnglesForDirection(ref angleMin, ref angleMax, direction); int prefabAmount = UnityEngine.Random.Range(info.PrefabAmountMin, info.PrefabAmountMax + 1); //List<GameObject> allFlings = new List<GameObject>(); GameObject[] allFlings = new GameObject[prefabAmount]; for (int i = 0; i < prefabAmount; i++) { Vector3 finalPosition = spawnPoint + new Vector3(UnityEngine.Random.Range(-info.OriginVariationX, info.OriginVariationX), UnityEngine.Random.Range(-info.OriginVariationY, info.OriginVariationY), 0f); //GameObject newFling = GameObject.Instantiate(info.Prefab, finalPosition,Quaternion.identity); GameObject newFling = info.Pool.Instantiate(finalPosition, Quaternion.identity); Rigidbody2D rigidbody = newFling.GetComponent <Rigidbody2D>(); if (rigidbody != null) { float velocity = UnityEngine.Random.Range(info.VelocityMin, info.VelocityMax); float angle = UnityEngine.Random.Range(angleMin, angleMax); var eulerAngles = newFling.transform.eulerAngles; eulerAngles.z = angle; newFling.transform.eulerAngles = eulerAngles; rigidbody.velocity = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad)) * velocity; } //allFlings.Add(newFling); allFlings[i] = newFling; } return(allFlings); }
public static GameObject[] SpawnFlings(FlingInfo fling, Vector3 spawnPoint, CardinalDirection direction) { return(SpawnFlingsInternal(fling, spawnPoint, direction)); }