private void Start() { if (explosive == null) { explosive = GetComponent <IExplosive>(); } if (explosive == null) { explosive = GetComponentInParent <IExplosive>(); } }
private IExplosive FindTarget() { int x = 0; int y = 0; var rotation = transform.rotation; if (rotation.y == 0 && rotation.z == 0) { x = 1; y = 0; } else if (rotation.y < 0 && rotation.z == 0) { x = -1; y = 0; } else if (rotation.y == 0 && rotation.z <= 0) { x = 0; y = -1; } else { x = 0; y = 1; } var pointX = transform.position.x + x * 0.85f; var pointY = transform.position.y + y * 0.85f; Vector2 bomb = new Vector2(transform.position.x, transform.position.y); Vector2 area = new Vector2(pointX, pointY); Collider2D[] coliders = Physics2D.OverlapAreaAll(bomb, area); foreach (var colider in coliders) { IExplosive explosive = colider.gameObject.GetComponent <IExplosive>(); if (explosive != null) { return(explosive); } } return(null); }
// Start is called before the first frame update void Start() { explosive = GetComponent <IExplosive>(); }
private void Kaboom() { IExplosive target = FindTarget(); target.explode(); }