Felix Boucher b54627196c population mechanic with art
- added art for house and UI
- put population in ResourceManager
- create house prefab
- added code for adding and removing pop depending on entity
- refactor harvesters so they inherit from ally
- modify placeholders and buttons so that only units cost population
- add events for population and resources changing
- add population relative configs to global config
- add start resources values to Levels
- add debug feature for generating resources for free
2023-10-29 19:12:32 -04:00

73 lines
2.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Handles what happens when the user clicks on a collider
/// </summary>
public class ClickBehavior : MonoBehaviour
{
private float unpausedTime = 1f;
private void Update()
{
if (Input.GetMouseButton(0))
{
Vector2 clickPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
List<Collider2D> listColliders = new(Physics2D.OverlapCircleAll(clickPoint, 0.05f));
List<Collider2D> resourceColliders = listColliders.FindAll(obj => obj.CompareTag("Resource"));
if (resourceColliders.Count > 0)
{
foreach (Collider2D collider in resourceColliders)
{
collider.GetComponent<ResourceMaker>().ClickOnResource();
}
}
}
}
public void ChangeGameSpeed()
{
if (Time.timeScale != 0f)
{
if (Time.timeScale == 1f)
{
GameObject.Find("btn_speedup").GetComponent<Button>().image.color = Color.yellow;
Time.timeScale = 1.5f;
}
else
{
GameObject.Find("btn_speedup").GetComponent<Button>().image.color = Color.white;
Time.timeScale = 1f;
}
unpausedTime = Time.timeScale;
}
}
public void StopGame()
{
if (Time.timeScale != 0f)
{
unpausedTime = Time.timeScale;
GameObject.Find("btn_pause").GetComponent<Button>().image.color = Color.black;
Time.timeScale = 0f;
}
else
{
GameObject.Find("btn_pause").GetComponent<Button>().image.color = Color.white;
Time.timeScale = unpausedTime;
}
}
/// <summary>
/// Remet la vitesse de jeux a son etat normal lorsque le dernier ennemi est mort, si necessaire
/// </summary>
public static void ResetGameSpeed()
{
GameObject.Find("btn_speedup").GetComponent<Button>().image.color = Color.white;
Time.timeScale = 1f;
}
}