TO SQUASH: Fixed oozeball split animation.

This commit is contained in:
2026-08-03 02:37:41 -04:00
parent 17051821b5
commit 6351d69fb1
5 changed files with 94 additions and 44 deletions
+1 -24
View File
@@ -49,28 +49,6 @@ AnimatorState:
m_MirrorParameter: m_MirrorParameter:
m_CycleOffsetParameter: m_CycleOffsetParameter:
m_TimeParameter: m_TimeParameter:
--- !u!1101 &-1226764820957732322
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
m_Solo: 0
m_Mute: 0
m_IsExit: 1
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 0
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!91 &9100000 --- !u!91 &9100000
AnimatorController: AnimatorController:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -110,8 +88,7 @@ AnimatorState:
m_Name: OozeBallSplit m_Name: OozeBallSplit
m_Speed: 1 m_Speed: 1
m_CycleOffset: 0 m_CycleOffset: 0
m_Transitions: m_Transitions: []
- {fileID: -1226764820957732322}
m_StateMachineBehaviours: [] m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0} m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0 m_IKOnFeet: 0
+8 -1
View File
@@ -105,4 +105,11 @@ AnimationClip:
m_EulerEditorCurves: [] m_EulerEditorCurves: []
m_HasGenericRootTransform: 0 m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0 m_HasMotionFloatCurves: 0
m_Events: [] m_Events:
- time: 0.6666667
functionName: Split
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
+54 -11
View File
@@ -39,7 +39,35 @@ public class BallSpawner : MonoBehaviour
StartCoroutine(SpawnBalls()); StartCoroutine(SpawnBalls());
} }
private void SpawnBall(GameObject ballPrefab) public void SpawnBallOfType(string ballType, Vector2? position = null)
{
switch (ballType)
{
case "BasicBall":
SpawnBall(basicBallPrefab, position);
break;
case "NuclearBall":
SpawnBall(nuclearBallPrefab, position);
break;
case "GlassBall":
SpawnBall(glassBallPrefab, position);
break;
case "EyeBall":
SpawnBall(eyeBallPrefab, position);
break;
case "OozeBall":
SpawnBall(oozeBallPrefab, position);
break;
case "FruitBall":
SpawnBall(fruitBallPrefab, position);
break;
default:
Debug.LogWarning($"Unknown ball type: {ballType}");
break;
}
}
private void SpawnBall(GameObject ballPrefab, Vector2? position = null)
{ {
if (ballPrefab == null || gameBoard == null) if (ballPrefab == null || gameBoard == null)
{ {
@@ -47,9 +75,20 @@ public class BallSpawner : MonoBehaviour
return; return;
} }
Vector3 spawnPosition = GetRandomPositionInsideGameBoard(); Vector3 spawnPosition = position.HasValue ?
new Vector3(position.Value.x, position.Value.y, gameBoard.transform.position.z) :
GetRandomPositionInsideGameBoard();
var newBall = Instantiate(ballPrefab, spawnPosition, Quaternion.identity); var newBall = Instantiate(ballPrefab, spawnPosition, Quaternion.identity);
if (ballPrefab == oozeBallPrefab)
{
var oozeBallScript = newBall.GetComponent<OozeBall>();
if (oozeBallScript != null)
{
oozeBallScript.spawner = this;
}
}
balls.Enqueue(newBall); balls.Enqueue(newBall);
} }
@@ -81,15 +120,7 @@ public class BallSpawner : MonoBehaviour
return new Vector3(randomX, randomY, gameBoard.transform.position.z); return new Vector3(randomX, randomY, gameBoard.transform.position.z);
} }
private IEnumerator SpawnBalls() public void FixCollisions() {
{
while (ballQueue.Count > 0)
{
System.Action spawnAction = ballQueue.Dequeue();
spawnAction.Invoke();
yield return _waitForSeconds0_5;
}
// Disable collision between existing balls of certain types. // Disable collision between existing balls of certain types.
// Only basic balls and fruit balls will collide with each other, while ooze, // Only basic balls and fruit balls will collide with each other, while ooze,
// nuclear, glass, and eye balls will not collide with any other balls. // nuclear, glass, and eye balls will not collide with any other balls.
@@ -117,4 +148,16 @@ public class BallSpawner : MonoBehaviour
} }
} }
} }
private IEnumerator SpawnBalls()
{
while (ballQueue.Count > 0)
{
System.Action spawnAction = ballQueue.Dequeue();
spawnAction.Invoke();
yield return _waitForSeconds0_5;
}
FixCollisions();
}
} }
+30 -8
View File
@@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using System.Collections;
public class OozeBall : MonoBehaviour public class OozeBall : MonoBehaviour
{ {
@@ -16,19 +17,24 @@ public class OozeBall : MonoBehaviour
public AudioClip stoppedSound; public AudioClip stoppedSound;
public BallSpawner spawner;
private AudioSource audioSource; private AudioSource audioSource;
private SpriteRenderer spriteRenderer;
private Vector2 speed; private Vector2 speed;
private float splitTimer = 30.0f; private float splitTimer = 10.0f;
private float tickTimer = 1.0f; private float tickTimer = 0.5f;
// Start is called once before the first execution of Update after the MonoBehaviour is created // Start is called once before the first execution of Update after the MonoBehaviour is created
void Start() void Start()
{ {
audioSource = GetComponent<AudioSource>(); audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>();
speed = new Vector2(Random.Range(-0.002f, 0.002f), Random.Range(-0.002f, 0.002f)); speed = new Vector2(Random.Range(-0.002f, 0.002f), Random.Range(-0.002f, 0.002f));
audioSource.PlayOneShot(spawnSound); audioSource.PlayOneShot(spawnSound);
@@ -39,7 +45,7 @@ public class OozeBall : MonoBehaviour
{ {
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.IsName("OozeBallMove")) { if (stateInfo.IsName("OozeBallMove") || stateInfo.IsName("OozeBallSplit")) {
transform.Translate(speed); transform.Translate(speed);
} }
@@ -48,13 +54,12 @@ public class OozeBall : MonoBehaviour
if (splitTimer <= 0.0f) if (splitTimer <= 0.0f)
{ {
Split(); animator.SetTrigger("split");
Destroy(gameObject);
} }
if (tickTimer <= 0.0f) if (tickTimer <= 0.0f)
{ {
tickTimer = 1.0f; tickTimer = 0.5f;
audioSource.PlayOneShot(timerSound); audioSource.PlayOneShot(timerSound);
} }
@@ -72,9 +77,26 @@ public class OozeBall : MonoBehaviour
void Split() void Split()
{ {
animator.SetTrigger("split"); StartCoroutine(SplitCoroutine());
}
private IEnumerator SplitCoroutine()
{
spriteRenderer.enabled = false;
audioSource.PlayOneShot(splitSound); audioSource.PlayOneShot(splitSound);
// TODO: Implement the logic for splitting the OozeBall into smaller balls
for (int i = 0; i < Random.Range(5, 8); i++)
{
Vector3 spawnPosition = transform.position +
new Vector3(Random.Range(-0.12f, 0.12f), Random.Range(-0.12f, 0.12f), 0);
spawner.SpawnBallOfType("BasicBall", spawnPosition);
}
spawner.FixCollisions();
yield return new WaitForSeconds(1.0f);
Destroy(gameObject);
} }
void Halt() void Halt()
+1
View File
@@ -9,6 +9,7 @@ TagManager:
- BasicBall - BasicBall
- FruitBall - FruitBall
- OozeBall - OozeBall
- GlassBall
layers: layers:
- Default - Default
- TransparentFX - TransparentFX