TO SQUASH: Fixed oozeball split animation.
This commit is contained in:
@@ -49,28 +49,6 @@ AnimatorState:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
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
|
||||
AnimatorController:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -110,8 +88,7 @@ AnimatorState:
|
||||
m_Name: OozeBallSplit
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions:
|
||||
- {fileID: -1226764820957732322}
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
|
||||
@@ -105,4 +105,11 @@ AnimationClip:
|
||||
m_EulerEditorCurves: []
|
||||
m_HasGenericRootTransform: 0
|
||||
m_HasMotionFloatCurves: 0
|
||||
m_Events: []
|
||||
m_Events:
|
||||
- time: 0.6666667
|
||||
functionName: Split
|
||||
data:
|
||||
objectReferenceParameter: {fileID: 0}
|
||||
floatParameter: 0
|
||||
intParameter: 0
|
||||
messageOptions: 0
|
||||
|
||||
@@ -39,7 +39,35 @@ public class BallSpawner : MonoBehaviour
|
||||
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)
|
||||
{
|
||||
@@ -47,9 +75,20 @@ public class BallSpawner : MonoBehaviour
|
||||
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);
|
||||
|
||||
if (ballPrefab == oozeBallPrefab)
|
||||
{
|
||||
var oozeBallScript = newBall.GetComponent<OozeBall>();
|
||||
if (oozeBallScript != null)
|
||||
{
|
||||
oozeBallScript.spawner = this;
|
||||
}
|
||||
}
|
||||
|
||||
balls.Enqueue(newBall);
|
||||
}
|
||||
|
||||
@@ -81,15 +120,7 @@ public class BallSpawner : MonoBehaviour
|
||||
return new Vector3(randomX, randomY, gameBoard.transform.position.z);
|
||||
}
|
||||
|
||||
private IEnumerator SpawnBalls()
|
||||
{
|
||||
while (ballQueue.Count > 0)
|
||||
{
|
||||
System.Action spawnAction = ballQueue.Dequeue();
|
||||
spawnAction.Invoke();
|
||||
yield return _waitForSeconds0_5;
|
||||
}
|
||||
|
||||
public void FixCollisions() {
|
||||
// Disable collision between existing balls of certain types.
|
||||
// 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.
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class OozeBall : MonoBehaviour
|
||||
{
|
||||
@@ -16,19 +17,24 @@ public class OozeBall : MonoBehaviour
|
||||
|
||||
public AudioClip stoppedSound;
|
||||
|
||||
public BallSpawner spawner;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
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
|
||||
void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
animator = GetComponent<Animator>();
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
speed = new Vector2(Random.Range(-0.002f, 0.002f), Random.Range(-0.002f, 0.002f));
|
||||
|
||||
audioSource.PlayOneShot(spawnSound);
|
||||
@@ -39,7 +45,7 @@ public class OozeBall : MonoBehaviour
|
||||
{
|
||||
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
|
||||
|
||||
if (stateInfo.IsName("OozeBallMove")) {
|
||||
if (stateInfo.IsName("OozeBallMove") || stateInfo.IsName("OozeBallSplit")) {
|
||||
transform.Translate(speed);
|
||||
}
|
||||
|
||||
@@ -48,13 +54,12 @@ public class OozeBall : MonoBehaviour
|
||||
|
||||
if (splitTimer <= 0.0f)
|
||||
{
|
||||
Split();
|
||||
Destroy(gameObject);
|
||||
animator.SetTrigger("split");
|
||||
}
|
||||
|
||||
if (tickTimer <= 0.0f)
|
||||
{
|
||||
tickTimer = 1.0f;
|
||||
tickTimer = 0.5f;
|
||||
audioSource.PlayOneShot(timerSound);
|
||||
}
|
||||
|
||||
@@ -72,9 +77,26 @@ public class OozeBall : MonoBehaviour
|
||||
|
||||
void Split()
|
||||
{
|
||||
animator.SetTrigger("split");
|
||||
StartCoroutine(SplitCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator SplitCoroutine()
|
||||
{
|
||||
spriteRenderer.enabled = false;
|
||||
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()
|
||||
|
||||
@@ -9,6 +9,7 @@ TagManager:
|
||||
- BasicBall
|
||||
- FruitBall
|
||||
- OozeBall
|
||||
- GlassBall
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
||||
Reference in New Issue
Block a user