Implemented OverlapCircleAll and FindAll Reverted SortingOrder changes to prefabs
26 lines
844 B
C#
26 lines
844 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// Handles what happens when the user clicks on a collider
|
|
/// </summary>
|
|
public class ClickBehavior : MonoBehaviour
|
|
{
|
|
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 != null)
|
|
{
|
|
foreach (Collider2D collider in resourceColliders)
|
|
{
|
|
collider.GetComponent<ResourceMaker>().GenerateResource();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|