private void InstantiatePickups() { SetCurrentIndexValue((int)currentIndex.Value + 1); int toCreate = wavePickupAmounts + 1; float angle = TimedBoundRandom.RandomFloat(0, 360); lastAngle = angle; float offsetInc = pickupOffset.y * 2.0f / (toCreate - 1); PickupRepresentationArr allPickups = isAssistMode.Value? assistModePickups : normalModePickups; List <PickupRepresentation> possiblePickups = new List <PickupRepresentation>(); possiblePickups.AddRange(allPickups.Pickups); for (int i = 0; i < toCreate; i++) { Vector2 anchorPos = Vector2.right * (wallVar.Value.Radius + pickupOffset.x) + Vector2.up * (-pickupOffset.y + offsetInc * i); anchorPos = MathUtils.Rotate(anchorPos, angle); Vector2 dir = (MathUtils.Rotate(Vector2.right, (angle + 180) % 360) - MathUtils.Rotate(Vector2.right, angle)).normalized; Keyframe lastKey = pickupSpeed.keys[pickupSpeed.keys.Length - 1]; float speed = pickupSpeed.Evaluate(Mathf.Clamp(CurrentWave, 0, lastKey.time)); bool isHealthPickup = (i == 1); RoundPickup pickup = null; if (isHealthPickup) { if (playTest.spawnHealthOpposite) { anchorPos += anchorPos.magnitude * dir * 2; dir = -dir; } pickup = Instantiate(healthPickup, (Vector3)anchorPos, Quaternion.identity); } else { pickup = Instantiate(roundPickupPrefab, (Vector3)anchorPos, Quaternion.identity); possiblePickups = PopulatePickup(pickup, possiblePickups); } pickup.SetupPickup(dir, speed); } SetIsInstantiatedValue(true); }
protected override void Apply(Transform col) { base.Apply(col); if (instantiated != null) { PickupText text = instantiated.GetComponent <PickupText>(); RoundPickup pickup = GetComponent <RoundPickup>(); if (pickup != null && pickup.PlayerStats != null && pickup.PlayerStats.increments.Length > 0 && pickup.PlayerStats.decrements.Length > 0) { bool isMax = pickup.PlayerStats.increments.Length > 0 && IsMaxStat(pickup.PlayerStats.increments[0]); bool isMin = pickup.PlayerStats.decrements.Length > 0 && IsMinStat(pickup.PlayerStats.decrements[0]); string top = (isMax? "Max " : "+ ") + pickup.topLabel; string bot = (isMin? "Min " : "- ") + pickup.botLabel; text.SetLabels(top, bot); } } }
private List <PickupRepresentation> PopulatePickup(RoundPickup pickup, List <PickupRepresentation> pickups) { if (pickups == null || pickups.Count <= 0) { return(pickups); } int chosenIndex = TimedBoundRandom.RandomInt(0, pickups.Count); PickupRepresentation representation = pickups[chosenIndex]; pickup.SetPlayerStats(representation.increments, representation.decrements, representation.image); pickup.topLabel = representation.topLabel; pickup.botLabel = representation.botLabel; pickups.RemoveAt(chosenIndex); return(pickups); }