2026-08-05 01:23:47 -04:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
2026-08-12 00:52:57 -04:00
|
|
|
public class VerticalBar : BarBase
|
2026-08-05 01:23:47 -04:00
|
|
|
{
|
|
|
|
|
public GameObject verticalBarrierPrefab;
|
|
|
|
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2026-08-12 00:52:57 -04:00
|
|
|
Initialize();
|
2026-08-05 01:23:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
if (canFire)
|
|
|
|
|
{
|
|
|
|
|
firingTimer += Time.fixedDeltaTime;
|
|
|
|
|
|
|
|
|
|
if (firingTimer >= firingSpeed)
|
|
|
|
|
{
|
|
|
|
|
if (canFireTop)
|
|
|
|
|
{
|
|
|
|
|
Vector3 topSide = new Vector3(
|
|
|
|
|
bounds.center.x,
|
|
|
|
|
bounds.max.y + (bounds.size.y / 2.0f),
|
|
|
|
|
bounds.center.z
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var top = Instantiate(verticalBarrierPrefab, topSide, Quaternion.identity);
|
|
|
|
|
var topBarScript = top.GetComponent<VerticalBar>();
|
|
|
|
|
topBarScript.firingSpeed = firingSpeed;
|
|
|
|
|
topBarScript.canFireBottom = false;
|
|
|
|
|
|
|
|
|
|
Physics2D.IgnoreCollision(
|
|
|
|
|
top.GetComponent<Collider2D>(),
|
|
|
|
|
GetComponent<Collider2D>(),
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (canFireBottom)
|
|
|
|
|
{
|
|
|
|
|
Vector3 bottomSide = new Vector3(
|
|
|
|
|
bounds.center.x,
|
|
|
|
|
bounds.min.y - (bounds.size.y / 2.0f),
|
|
|
|
|
bounds.center.z
|
|
|
|
|
);
|
|
|
|
|
var bottom = Instantiate(verticalBarrierPrefab, bottomSide, Quaternion.identity);
|
|
|
|
|
var bottomBarScript = bottom.GetComponent<VerticalBar>();
|
|
|
|
|
bottomBarScript.firingSpeed = firingSpeed;
|
|
|
|
|
bottomBarScript.canFireTop = false;
|
|
|
|
|
|
|
|
|
|
Physics2D.IgnoreCollision(
|
|
|
|
|
bottom.GetComponent<Collider2D>(),
|
|
|
|
|
GetComponent<Collider2D>(),
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
canFire = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|