Pull request #38: Fixed resource collecting bug

Merge in CGD/gather-and-defend from feature/fixRecolteBug to main

* commit '5deeb528b8783c2e3c2e54753e7c369b4c910d59':
  Ajusted the behavior to be performance efficient
  Fixed yield collecting bug
  Ajustement de l'ordre des sprite des recoltes
This commit is contained in:
Ader Alisma 01 2023-08-02 19:06:57 +00:00
commit 76c90cacdd

View File

@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary> /// <summary>
/// Handles what happens when the user clicks on a collider /// Handles what happens when the user clicks on a collider
@ -9,13 +10,15 @@ public class ClickBehavior : MonoBehaviour
if (Input.GetMouseButton(0)) if (Input.GetMouseButton(0))
{ {
Vector2 clickPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 clickPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(clickPoint, transform.up); List<Collider2D> listColliders = new(Physics2D.OverlapCircleAll(clickPoint, 0.05f));
if (hit.collider != null) List<Collider2D> resourceColliders = listColliders.FindAll(obj => obj.CompareTag("Resource"));
if (resourceColliders.Count > 0)
{ {
if (hit.collider.CompareTag("Resource")) foreach (Collider2D collider in resourceColliders)
{ {
hit.collider.GetComponent<ResourceMaker>().GenerateResource(); collider.GetComponent<ResourceMaker>().GenerateResource();
} }
} }
} }
} }