fix detection range

problem :

detection range didn't show anymore on placeholders

solution :

calculate detection range from collider's offset and size instead of it's bound
This commit is contained in:
Felix Boucher 2023-10-30 21:28:21 -04:00
parent 96d9b0fd7b
commit 3c1a94257f
2 changed files with 6 additions and 5 deletions

View File

@ -10,11 +10,12 @@ public class Detection : MonoBehaviour
{
get
{
if (!_collider) _collider = GetComponent<BoxCollider2D>();
var bounds = _collider.bounds;
return new Rect(bounds.min - transform.position, bounds.size);
var _coll = GetComponent<BoxCollider2D>();
var rect = new Rect(_coll.offset, _coll.size);
return rect;
}
}
[SerializeField]
private Entity _entityLinked;
protected virtual void Start()

View File

@ -58,11 +58,11 @@ public class GameObjectPlacementButton : UnitPlacementButton
var rend = detection.AddComponent<SpriteRenderer>();
rend.sprite = _detectionRangeSprite;
rend.sortingLayerName = "Character";
rend.sortingOrder = 0;
rend.sortingOrder = 1;
rend.color = new Color(1, 1, 1, 0.2f);
detection.transform.SetParent(placeholder.transform);
detection.transform.localPosition = detectionRect.center;
detection.transform.localPosition = detectionRect.position;
detection.transform.localScale = detectionRect.size;
}
}