Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class DetectCollisions : MonoBehaviour
- {
- private GameManager gameManager;
- void Start()
- {
- //refernecing the game manager
- gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
- }
- void Update()
- {
- }
- //when the food and the animal collide they disappear and add score
- //when the player and animal collide they lose lives
- //when player destroys an animal they gain 5 points
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Player"))
- {
- gameManager.AddLives(-1);
- Destroy(gameObject);
- }
- else if (other.CompareTag("Animal"))
- {
- other.GetComponent<AnimalHunger>().FeedAnimal(1);
- Destroy(gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement