IEnumerator behaviorRoutine() { while (true) { if (shouldSwitchTarget()) { switchTarget(); } patienceTicker--; yield return(new WaitForSeconds(RandomExtra.Range(ChaseFrameTimeRange))); } }
MagicColor getColor() { colorStreak++; var chance = ChanceToSwitchColorsByColorStreak.Evaluate(colorStreak); if (RandomExtra.Chance(chance)) { currentColor = colors.GetNext(); colorStreak = 0; } return(currentColor); }
IEnumerator Start() { var text = GetComponent <TextMeshProUGUI>(); while (true) { var next = Fonts.GetNext(); text.font = next.Font; text.fontSize = next.Size; yield return(new WaitForSeconds(RandomExtra.Range(FontSwapTimeRange))); } }
void setScale(float dt) { scaleDelta += (RandomExtra.Chance(.5f) ? -ScaleAccelMax : ScaleAccelMax) * dt; scaleDelta = Mathf.Clamp(scaleDelta, ScaleDeltaBounds.x, ScaleDeltaBounds.y); var next = transform.localScale * scaleDelta; transform.localScale += (next - transform.localScale) * dt; transform.localScale = new Vector3 ( Mathf.Clamp(transform.localScale.x, ScaleBounds.x, ScaleBounds.y), Mathf.Clamp(transform.localScale.y, ScaleBounds.x, ScaleBounds.y), Mathf.Clamp(transform.localScale.z, ScaleBounds.x, ScaleBounds.y) ); }
public void Launch() { transform.parent = null; launched = true; rb.simulated = true; rb.velocity = LaunchSpeed; // half the time, flip x: if (RandomExtra.Chance(.5f)) { rb.velocity *= Vector2.left; } GetComponent <DestroyWhenChildrenInvisible>().ShouldDestroy = true; }
void Start() { List <AstronomicalBody> prefabs = getPrefabsToSpawn(); List <AstronomicalBody> spawned = new List <AstronomicalBody>(); int attemptedSpawnConfigurations = 0; while (spawned.Count < prefabs.Count && attemptedSpawnConfigurations < 1000) { List <Vector3> unitSphereDistribution = fibonacciSphere(prefabs.Count, true); for (int i = 0; i < prefabs.Count; i++) { Vector3 point; int tryCount = 0; do { point = transform.position + unitSphereDistribution[i] * RandomExtra.Range(DistanceFromSpawnRange); tryCount++; } while (Physics.CheckSphere(point, prefabs[i].MinDistanceFromOtherColliders) && tryCount < SPAWN_TRIES_PER_PLANET); if (tryCount >= SPAWN_TRIES_PER_PLANET) { foreach (AstronomicalBody spawn in spawned) { DestroyImmediate(spawn.gameObject); } spawned = new List <AstronomicalBody>(); attemptedSpawnConfigurations++; break; } spawned.Add(Instantiate(prefabs[i], point, UnityEngine.Random.rotation)); } } Debug.Log(attemptedSpawnConfigurations); if (attemptedSpawnConfigurations >= 1000) { throw new Exception("couldn't find a working configuration in a reasonable amount of time"); } Goals = getGoals(prefabs); }
// returns the piece that is hit from cover fire, if there is one, otherwise null public BoardPiece TryHit() { // check middle first since we like it more if (RandomExtra.Chance(middleChance)) { return(MiddleCover); } if (RandomExtra.Chance(leftChance)) { return(LeftCover); } if (RandomExtra.Chance(rightChance)) { return(RightCover); } return(null); }
void redistributeSpinWith(Top otherTop) { collisionLock = true; otherTop.collisionLock = true; bool thisSpunFaster = CurrentSpin == otherTop.CurrentSpin ? RandomExtra.Chance(.5f) // ties are broken randomly : CurrentSpin > otherTop.CurrentSpin; Top fasterSpinningTop = thisSpunFaster ? this : otherTop; Top slowerSpinningTop = thisSpunFaster ? otherTop : this; Spin differential = Mathf.Min(fasterSpinningTop.CurrentSpin, Spin.MAX - slowerSpinningTop.CurrentSpin); fasterSpinningTop.CurrentSpin -= differential; slowerSpinningTop.CurrentSpin += differential; }
void die() { Destroy(gameObject); foreach (ResourceType type in EnumUtil.AllValues <ResourceType>()) { for (int i = 0; i < ResourceProfile[type]; i++) { Vector3 explosion = Random.onUnitSphere * RandomExtra.Range(ParticleExplosiveForceRange); var particle = Instantiate(ParticlePrefab, transform.position, Quaternion.LookRotation(explosion)); particle.Initialize(Player.Instance.transform, type); particle.Rigidbody.AddForce(explosion, ForceMode.VelocityChange); } } PlanetExplosionEffect.Instance.Play(transform.position); }
void explode() { int amount = RandomExtra.Range(PartsReleasedRange); for (int i = 0; i < amount; i++) { var fragment = Object.Instantiate(PartsList.PickRandom(), transform.position, Quaternion.identity); var explosiveVelocity = Quaternion.AngleAxis(Random.Range(-ArcRange, ArcRange), Vector3.forward) * lastCollisionNormal; if (explosiveVelocity.magnitude > fragment.MaxBurstSpeed) { explosiveVelocity = explosiveVelocity.normalized * fragment.MaxBurstSpeed; } fragment.Rigidbody.velocity = explosiveVelocity; } }
public void UseOn(IHackable target) { MethodInfo hackMethod = target.GetType().GetMethod(HackMethodName); hackMethod.Invoke(target, PassParam ? new object[] { HackMethodParam } : null); bool caught = RandomExtra.Chance(RevealChance); bool patched = RandomExtra.Chance(PatchChance); if (caught) { SecurityManager.Instance.Alert = true; } if (patched) { InventoryManager.Instance.HacksToBePatched.Add(this); Debug.Log("you got patched son"); } }
public void Initialize(HamsterFart parent, Vector2 velocity, MagicColor color) { this.parent = parent; ColorPart.ChangeColor(color); bool use1 = RandomExtra.Chance(.5f); Outline.sprite = use1 ? Outline1 : Outline2; Cloud.sprite = use1 ? Cloud1 : Cloud2; Outline.SetAlpha(Alpha); Cloud.SetAlpha(Alpha); GetComponent <Collider2D>().isTrigger = true; // just in case GetComponent <Rigidbody2D>().velocity = velocity; Destroy(gameObject, RandomExtra.Range(LifeTimeRange)); }
IEnumerator animateSpriteRendererInternal(float showDelay, SpriteRenderer spriteRenderer, bool loading) { Sprite finalSprite = loading ? spriteRenderer.sprite : null; if (loading) { spriteRenderer.sprite = null; } yield return(new WaitForSeconds(showDelay)); var frames = loading ? LevelLoadAnimation : LevelUnloadAnimation; foreach (var frame in frames) { spriteRenderer.sprite = frame.Sprite; yield return(new WaitForSeconds(RandomExtra.Range(FrameTimeRange))); } spriteRenderer.sprite = finalSprite; }
void OnTriggerEnter2D(Collider2D other) { bool effect = false; if (!appliedExtraEffect && RandomExtra.Chance(ExtraEffectChance)) { appliedExtraEffect = false; effect = true; } if (other.gameObject.layer == LayerMask.NameToLayer("Player")) { if (effect && Color == MagicColor.Green) { other.GetComponent <Mage>().Health.Heal(HealAmount); } return; } BaseEnemy enemy = other.gameObject.GetComponent <BaseEnemy>(); if (enemy != null) { enemy.Health.ColorDamage(Damage, Color); if (effect) { if (Color == MagicColor.Red) { enemy.ApplyFire(Random.Range(FireTimeMin, FireTimMax)); } if (Color == MagicColor.Blue) { enemy.ApplyIce(Random.Range(IceTimeMin, IceTimeMax)); } } } Destroy(gameObject); }
void manageWandering() { if (Mover.Velocity != 0) { wanderWaitTimer = RandomExtra.Range(TimeUntilWanderRange); if (wandering) { wandering = false; StopAllCoroutines(); } } else { wanderWaitTimer -= Time.deltaTime; if (wanderWaitTimer <= 0 && !wandering) { wandering = true; StartCoroutine(wander()); returnToNormalColorTimer = RandomExtra.Range(TimeToReturnToNormalColorRange); } } if (wandering) { Visual.transform.localPosition = wanderLocalPosition; Visual.transform.position = new Vector3 ( Mathf.Round(Visual.transform.position.x * 8) / 8, Mathf.Round(Visual.transform.position.y * 8) / 8, Mathf.Round(Visual.transform.position.z * 8) / 8 ); } else { returnToNormalColorTimer -= Time.deltaTime; } }
// for spooky effects protected string randomAscii(int length, bool includeSpace = true) { Vector2Int printableCharacterRange = new Vector2Int ( 32 + (includeSpace ? 0 : 1), 127 // don't include delete (random is exclusive) ); StringBuilder sb = new StringBuilder(); bool colorAdded = false; for (int i = 0; i < length; i++) { if (!colorAdded && RandomExtra.Chance(.02f)) { var color = MagicColorRamp.GetValue(Random.value); sb.Append($"<#{ColorUtility.ToHtmlStringRGB(color)}>"); colorAdded = true; } sb.Append((char)RandomExtra.Range(printableCharacterRange)); if (colorAdded && RandomExtra.Chance(.07f)) { sb.Append("</color>"); colorAdded = false; } } if (colorAdded) { sb.Append("</color>"); colorAdded = false; } return(sb.ToString()); }
IEnumerator Start() { yield return(new WaitForSeconds(Cooldown)); bool order = false; while (true) { bool coinChance = RandomExtra.Chance(CoinGameProbability.Evaluate(ScoreManager.Instance.CoinCount)); bool washChance = RandomExtra.Chance(WashGameProbability.Evaluate(ScoreManager.Instance.Dirtiness)); // might be unnecessary, but we'll switch which game we check first every time so we don't favor one over the other if (order = !order) { if (coinChance) { SceneManager.LoadScene("Coin"); } else if (washChance) { SceneManager.LoadScene("Bath"); } } else { if (washChance) { SceneManager.LoadScene("Bath"); } else if (coinChance) { SceneManager.LoadScene("Coin"); } } yield return(new WaitForSeconds(SecondsPerRoll)); } }
IEnumerator deathRoutine() { Collider.enabled = false; yield return(new WaitForSeconds(DeathAnimationWaitTimeBeforeShrinking)); float explosionChance = ChanceForDeathToBeExplosionDeathByDeathsSinceLastExplosionDeath.Evaluate(deathsSinceLastExplosionDeath); bool exploding = RandomExtra.Chance(explosionChance); float targetScale = exploding ? ExplosionDeathScaleTarget : NormalDeathScaleTarget; DeathScaleTransition.StartTransitionTo(targetScale); yield return(new WaitWhile(() => DeathScaleTransition.Transitioning)); deathsSinceLastExplosionDeath = exploding ? 0 : deathsSinceLastExplosionDeath + 1; BallDied.Raise(); Destroy(gameObject); }
void switchTarget() { if (RandomExtra.Chance(PlayerGuaranteedTargetChance)) { target = FindObjectOfType(typeof(Player)) as FlockLeader; return; } var potentialTargets = (FindObjectsOfType(typeof(FlockLeader)) as FlockLeader[]).ToList(); potentialTargets.Remove(this); Func <FlockLeader, bool> inRange = fl => Vector3.Distance(fl.transform.position, transform.position) <= DesiredMaximumDistance; if (!potentialTargets.Where(fl => fl != target).Any(inRange)) { target = potentialTargets.PickRandom(); } else { target = potentialTargets.Where(fl => fl != target).Where(inRange).ToList().PickRandom(); } }
IEnumerator ambleRoutine() { while (true) { currentSpeed = 0; animator.SetBool("Walking", false); yield return(new WaitForSeconds(RandomExtra.Range(AmblePauseTimeRange))); float mult = walkingDirection; if (isFrozen) { mult *= BaseMageBullet.IceSlowPercent; } walkingDirection *= -1; currentSpeed = AmbleSpeed * mult; animator.SetBool("Walking", true); yield return(new WaitForSeconds(AmbleTime * (isFrozen ? BaseMageBullet.IceSlowPercent : 1))); } }
public void SpawnEnemy(Vector3 position) { spawnFlock(position, EnemyLeaderPrefab, RandomExtra.Range(EnemyFlockSizeRange)); }
IEnumerator moveRoutine() { moving = true; moveDir = RandomExtra.Chance(.5f) ? Vector2.right : Vector2.left; float mainTimer = Random.Range(MoveTimeRange.x, MoveTimeRange.y); float directionTimer = Random.Range(DirectionSwitchTimeRange.x, DirectionSwitchTimeRange.y); while (mainTimer > 0) { if (Mathf.Abs(transform.position.x - PlayerRef.transform.position.x) <= AttackDistance && RandomExtra.ChancePerSecond(AttackChancePerSecond)) { moving = false; yield break; // do a grab, as long as the parent immediately calls grab } mainTimer -= Time.deltaTime; directionTimer -= Time.deltaTime; if (directionTimer <= 0) { directionTimer = Random.Range(DirectionSwitchTimeRange.x, DirectionSwitchTimeRange.y); moveDir *= -1; } transform.position += (Vector3)moveDir * MoveSpeed * Time.deltaTime; yield return(null); } moving = false; }
IEnumerator playAnimation(bool loading) { if (TilemapCollider != null) { TilemapCollider.enabled = false; } List <IndividualTileAnimationTracker> animationData = new List <IndividualTileAnimationTracker>(); foreach (var cellPosition in Tilemap.cellBounds.allPositionsWithin) { var tile = Tilemap.GetTile(cellPosition); if (tile == null) { continue; } animationData.Add(new IndividualTileAnimationTracker { Position = cellPosition, FinalTile = loading ? tile : null, CurrentFrame = -1, Frames = loading ? Animation.LevelLoadAnimation : Animation.LevelUnloadAnimation }); if (loading) { Tilemap.SetTile(cellPosition, null); } } yield return(new WaitForSeconds(ShowDelay)); Vector3Int[] positionArray = new Vector3Int[animationData.Count]; TileBase[] tileArray = new TileBase[animationData.Count]; int cursor = 0; while (animationData.Count > 0) { foreach (var data in animationData) { data.Timer -= Time.deltaTime; if (data.Timer > 0) { continue; } data.Timer = RandomExtra.Range(Animation.FrameTimeRange); data.CurrentFrame++; positionArray[cursor] = data.Position; tileArray[cursor] = data.CurrentTile; cursor++; } Tilemap.SetTiles(positionArray, tileArray); animationData.RemoveAll(anim => anim.IsFinished); yield return(null); Array.Clear(positionArray, 0, cursor); Array.Clear(tileArray, 0, cursor); cursor = 0; } if (TilemapCollider != null && loading) { TilemapCollider.enabled = true; } }