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:
parent
937624f54f
commit
bff2df154a
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -18,3 +18,4 @@ MonoBehaviour:
|
||||
_spawnOnStart: 0
|
||||
_spawnSpeed: 0.02
|
||||
_spawnCounter: 0
|
||||
_debugPrefab: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
|
||||
|
||||
@ -18,3 +18,4 @@ MonoBehaviour:
|
||||
_spawnOnStart: 1
|
||||
_spawnSpeed: 0
|
||||
_spawnCounter: 0
|
||||
_debugPrefab: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user