Pull request #52: fix detection range

Merge in CGD/gather-and-defend from prog/fix_detection_range to main

* commit '4568c350bfec91842dc9a8fe0917798fbfce7dda':
  toggle collider in coroutine instead of script
  fix detection range
This commit is contained in:
Felix-gabriel Boucher-luneau 2023-11-13 22:38:51 +00:00 committed by William Gingras 01
commit e1ae20e101
5 changed files with 35 additions and 1 deletions

View File

@ -103,12 +103,19 @@ 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;
StartCoroutine(ToggleCollider());
}
}
}
}
IEnumerator ToggleCollider()
{
_collider.enabled = false;
yield return null;
_collider.enabled = true;
}
//Getter and Setter
public Entity EntityLinked

View File

@ -8,9 +8,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)
@ -22,6 +23,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
}
/// <summary>

View File

@ -143,4 +143,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}