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:
commit
e1ae20e101
@ -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
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -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