fix detection range

besoin :

- quand une unité meurt, la prochaine unité n'est pas targetted

solution :

- deactivate and reactivate collider to re-trigger collision
This commit is contained in:
Felix Boucher 2023-11-05 11:52:48 -05:00
parent 937624f54f
commit bff2df154a
5 changed files with 30 additions and 1 deletions

View File

@ -103,6 +103,8 @@ public class Detection : MonoBehaviour
if(_projectileDamage == 0) {
if ((other.gameObject.tag == "Opponent" && _entityLinked is Ally) || (other.gameObject.tag == "Ally" && _entityLinked is Opponent)) {
_entityLinked.IsEnemyDetected = false;
enabled = false;
enabled = true;
}
}
}

View File

@ -11,9 +11,10 @@ public class ClickBehavior : MonoBehaviour
private void Update()
{
Vector2 clickPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
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)
@ -25,6 +26,20 @@ public class ClickBehavior : MonoBehaviour
}
}
#if UNITY_EDITOR
if (Input.GetMouseButtonUp(0))
{
const float clickRangeForSpawn = 0.7f;
var spawners = LevelManager.Instance.GetAll<SpawnerTile>();
var closest = spawners.Minimum(spawn => Vector2.Distance(spawn.Position, transform.position));
var distance = Vector2.Distance(clickPoint, closest.Position);
if (distance < clickRangeForSpawn)
{
closest.TriggerSpawnDebug();
}
}
#endif
}
public void ChangeGameSpeed()

View File

@ -136,4 +136,14 @@ public class SpawnerTile : LevelTile
{
enemy.Create(Position, parent: LevelManager.Instance.LevelTransform);
}
#if UNITY_EDITOR
[Header("DEBUG")]
[SerializeField]
private GameObject _debugPrefab;
public void TriggerSpawnDebug()
{
_debugPrefab.Create(Position, parent: LevelManager.Instance.LevelTransform);
}
#endif
}

View File

@ -18,3 +18,4 @@ MonoBehaviour:
_spawnOnStart: 0
_spawnSpeed: 0.02
_spawnCounter: 0
_debugPrefab: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}

View File

@ -18,3 +18,4 @@ MonoBehaviour:
_spawnOnStart: 1
_spawnSpeed: 0
_spawnCounter: 0
_debugPrefab: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}