TO SQUASH: Fixed issue with yummy missed sound playing multiple times.
This commit is contained in:
@@ -6,8 +6,6 @@ public class SharkSpawner : MonoBehaviour
|
||||
|
||||
public SpriteRenderer gameBoardSpriteRenderer;
|
||||
|
||||
private Bounds sharkBounds;
|
||||
|
||||
private Bounds gameBoardBounds;
|
||||
|
||||
private float spawnTimer = 0f;
|
||||
@@ -22,7 +20,6 @@ public class SharkSpawner : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
gameBoardBounds = gameBoardSpriteRenderer.bounds;
|
||||
sharkBounds = sharkPrefab.GetComponent<SpriteRenderer>().bounds;
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -37,6 +34,9 @@ public class SharkSpawner : MonoBehaviour
|
||||
if (Random.value < spawnProbability)
|
||||
{
|
||||
GameObject shark = Instantiate(sharkPrefab, spawnPosition, Quaternion.identity);
|
||||
Shark sharkScript = shark.GetComponent<Shark>();
|
||||
sharkScript.gameBoardSpriteRenderer = gameBoardSpriteRenderer;
|
||||
sharkScript.player = FindAnyObjectByType<Player>();
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
@@ -46,14 +46,19 @@ public class SharkSpawner : MonoBehaviour
|
||||
{
|
||||
isActive = true;
|
||||
spawnTimer = 0f;
|
||||
|
||||
Vector2 boardCenter = gameBoardBounds.center;
|
||||
Vector2 spawnAreaSize = gameBoardBounds.size * (2f / 3f);
|
||||
Vector2 halfSpawnArea = spawnAreaSize * 0.5f;
|
||||
|
||||
spawnPosition = new Vector2(
|
||||
Random.Range(
|
||||
gameBoardBounds.min.x + sharkBounds.extents.x,
|
||||
gameBoardBounds.max.x - sharkBounds.extents.x
|
||||
boardCenter.x - halfSpawnArea.x,
|
||||
boardCenter.x + halfSpawnArea.x
|
||||
),
|
||||
Random.Range(
|
||||
gameBoardBounds.min.y + sharkBounds.extents.y,
|
||||
gameBoardBounds.max.y - sharkBounds.extents.y
|
||||
boardCenter.y - halfSpawnArea.y,
|
||||
boardCenter.y + halfSpawnArea.y
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user