63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class FruitCollector : MonoBehaviour
|
|
{
|
|
public Fruits fruits;
|
|
|
|
|
|
void Start()
|
|
{
|
|
fruits = GameObject.Find("ScriptHolder").GetComponent<Fruits>();
|
|
|
|
|
|
}
|
|
|
|
// This method is called when another collider enters the trigger collider
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
// Check the name of the object that collided
|
|
switch (other.gameObject.name)
|
|
{
|
|
case "Apple":
|
|
fruits.isAppleCollected = true;
|
|
Debug.Log("Apple collected!");
|
|
other.gameObject.SetActive(false);
|
|
break;
|
|
|
|
case "Banana":
|
|
fruits.isBananaCollected = true;
|
|
Debug.Log("Banana collected!");
|
|
other.gameObject.SetActive(false);
|
|
break;
|
|
|
|
case "Cheese":
|
|
fruits.isCheeseCollected = true;
|
|
Debug.Log("Cheese collected!");
|
|
other.gameObject.SetActive(false);
|
|
break;
|
|
|
|
case "Cherry":
|
|
fruits.isCherryCollected = true;
|
|
Debug.Log("Cherry collected!");
|
|
other.gameObject.SetActive(false);
|
|
break;
|
|
|
|
case "Melon":
|
|
fruits.isMelonCollected = true;
|
|
Debug.Log("Melon collected!");
|
|
other.gameObject.SetActive(false);
|
|
break;
|
|
|
|
|
|
default:
|
|
// Handle other objects if needed
|
|
Debug.Log("Non-fruit object collided: " + other.gameObject.name);
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|