Made fruit be randomised

This commit is contained in:
2026-04-12 14:21:33 +01:00
parent 559248cbae
commit c68d64ab1d
8 changed files with 325 additions and 169 deletions

View File

@@ -1,8 +1,6 @@
using Fruitomation.Global;
using PashaBibko.Pacore.Attributes;
using UnityEngine.UI;
using Fruitomation.Global;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Fruitomation.Game
{
@@ -11,7 +9,6 @@ namespace Fruitomation.Game
[Header("References")]
[SerializeField] private RectTransform RectTransform;
[SerializeField] private Rigidbody2D Body2D;
[SerializeField] private Button Button;
[Header("Read only")]
[InspectorReadOnly, SerializeField] private Canvas AttachedCanvas;

View File

@@ -14,7 +14,7 @@ namespace Fruitomation.Game
[Header("References")]
[SerializeField] private Transform FruitSpawnParent;
[SerializeField] private GameObject FruitPrefab;
[SerializeField] private GameObject[] FruitPrefabs;
[SerializeField] private Canvas GameCanvas;
[Header("Read only")]
@@ -38,9 +38,11 @@ namespace Fruitomation.Game
private void SpawnFruit()
{
GameObject go = Instantiate(FruitPrefab, FruitSpawnParent);
GameObject prefab = FruitPrefabs[Random.Range(0, FruitPrefabs.Length)];
GameObject go = Instantiate(prefab, FruitSpawnParent);
FruitBehaviour behaviour = go.GetComponent<FruitBehaviour>();
Debug.Assert(behaviour != null, "Could not find FruitBehaviour");
Debug.Assert(behaviour is not null, "Could not find FruitBehaviour");
ActiveFruits.Add(behaviour);
behaviour.InitFruitBehaviour