using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEditor.ShaderKeywordFilter; using System.Linq; public class GameController : MonoBehaviour { /* * Slots to drag controllers into (e.g. UI) */ [Header("Other Controllers")] public UIController UIDisplay; private Drill _selectedDrill; private List _allDrills; [Header("Debugging Variables")] [SerializeField] private int _playerMoney = 0; [SerializeField] private int _rock; [SerializeField] private int _iron; [SerializeField] private int _silver; [SerializeField] private int _gold; [SerializeField] private int _gem; public int GetDrillCount() { if(_allDrills == null) { // each time we ask for the drill count, we'll check the scene to see if the number of drills has changed _allDrills = GameObject.FindObjectsOfType().ToList(); } return _allDrills.Count; } public int GetPlayerMoney() { return _playerMoney; } public int GetRock() { return _rock; } public int GetIron() { return _iron; } //TODO: Add the missing accessor methods public void AddRock(int amount) { _rock += amount; } public void AddIron(int amount) { _iron += amount; } //TODO: Add the missing modifier methods // Method to handle button clicks public void OnUpgradeCoolingClicked() { _selectedDrill.AddCoolingUpgrade(); } //TODO: Add the missing button handler method /** * THE CODE BELOW THIS SHOULDN'T NEED TO BE CHANGED * The code below will manage drill selection and deselection */ private void Update() { if(Input.GetMouseButtonDown(0)) { HandleClick(); } } private void HandleClick() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, out RaycastHit hit)) { // Try to find a Drill on the hit object or its parents Drill drill = hit.collider.GetComponentInParent(); if(drill != null) { SetSelected(drill); return; // done } } // If we got here, we either hit nothing or hit a non-drill -> clear selection ClearSelected(); } public void SetSelected(Drill drill) { if(_selectedDrill == drill) return; // already selected // Unhighlight previous drill if(_selectedDrill != null) { _selectedDrill.SetSelected(false); } // Set new selection _selectedDrill = drill; // Highlight new drill if(_selectedDrill != null) { _selectedDrill.SetSelected(true); } //TODO: Uncomment this line once you have the UI working //UIDisplay.UpdateUI(); } public Drill GetSelectedDrill() { return _selectedDrill; } public void ClearSelected() { SetSelected(null); } }