public void HulkSmash() { GameObject[] blobbies = GameObject.FindGameObjectsWithTag("Blobby"); if (blobbies.Length <= 1) { return; } GameObject victim = blobbies[Random.Range(0, blobbies.Length)]; while (victim == gameObject) { victim = blobbies[Random.Range(0, blobbies.Length)]; } Blobby b = victim.GetComponent <Blobby>(); log.AddEvent($"{blobbyName} gets mad at {b.blobbyName} and attacks!"); wanderLocation = victim.transform.position; attackTime = 0; isWandering = true; speed = Random.Range(maxMovementSpeed / 2, maxMovementSpeed); wanderingTime = wanderCooldown; }
private void OnCollisionEnter2D(Collision2D collision) { Blobby b = collision.gameObject.GetComponent <Blobby>(); if (b == null) { return; } TrappedBlobby trapped = Instantiate(trappedPrefab); trapped.color = b.color; trapped.worth = b.chonk; trapped.gameObject.transform.position = transform.position; shop.MakeMoney((int)b.GetBlobWorth()); data.blobbiesSacrificed += 1; sound.PlayTrapClip(); Destroy(gameObject); Destroy(b.gameObject); Destroy(trapped.gameObject, 10); }
void CompleteGame() { GameObject[] blobs = GameObject.FindGameObjectsWithTag("Blobby"); gameData.blobbiesKeptAlive = blobs.Length; foreach (GameObject go in blobs) { Blobby blob = go.GetComponent <Blobby>(); gameData.finalScore += (int)(blob.GetBlobWorth() * 2) + shop.coins; } SceneManager.LoadScene("GameComplete"); }
void Update() { foreach (QueuedBlobby b in queuedBlobbies) { float progress = b.PercentComplete(); if (b.Label != null) { b.Label.UpdateProgress(progress); } if (progress >= 1) { doneBlobbys.Add(b); } b.CurrentTime += Time.deltaTime; } bool didOne = false; foreach (QueuedBlobby b in doneBlobbys) { GameObject objBlobby = Instantiate(blobbyPrefab); Blobby freshBlobby = objBlobby.GetComponent <Blobby>(); freshBlobby.transform.position = new Vector2(transform.position.x, transform.position.y) + Random.insideUnitCircle.normalized * 3; freshBlobby.color = b.Color; freshBlobby.blobbyName = b.Name; log.AddEvent($"{b.Name} is born!"); queuedBlobbies.Remove(b); didOne = true; sound.PlayNameClip(b.NameIndex); } doneBlobbys.Clear(); if (didOne && hud.currentMenu == Menu.Spawner) { hud.ToggleMenu(Menu.None, new List <GameObject>()); CleanGameObjectRefs(); UpdateMenu(); } if (queuedBlobbies.Count > 0) { StartSpawner(); } else { StopSpawner(); } }
public void Update(Transform parent) { foreach (EnemySpawner currentSpawner in spawners) { if (currentSpawner.spawned == false && Time.time > currentSpawner.SpawnTime) { var child = Blobby.Instantiate(currentSpawner.EnemyPrefab, currentSpawner.position, Quaternion.identity); child.transform.parent = parent; EnemyCount++; child.OnDeath += OnChildDeath; child.behaviour = currentSpawner.behaviour; currentSpawner.spawned = true; } } spawners.RemoveAll(spawner => spawner.spawned); }
private void OnCollisionEnter2D(Collision2D collision) { Food f = collision.gameObject.GetComponent <Food>(); Blobby b = collision.gameObject.GetComponent <Blobby>(); if (f != null) { float foodValue = Random.Range(f.replenish * .75f, f.replenish * 1.25f); if (f.type == FoodType.Heal) { currentHP += foodValue; if (currentHP > maxHP) { currentHP = maxHP; } sound.PlayRandomHealClip(); } else { currentHunger += foodValue; if (currentHunger > maxHunger) { chonk += foodValue / 200; } sound.PlayRandomFoodClip(); } isWandering = false; Destroy(f.gameObject); } if (b != null && Random.value > blobbyBumpChance && attackTime <= 0) { b.currentHP -= Random.Range(blobbyAttack * 0.5f, blobbyAttack * 1.5f) * chonk; attackTime += Random.Range(attackCooldown * 0.5f, attackCooldown * 1.5f); log.AddEvent($"{blobbyName} attacks {b.blobbyName}!"); sound.PlayRandomHitClip(); } }