Files
Barrack-Unity/Assets/Scripts/Game/Player/HorizontalLaser.cs
T

59 lines
1.7 KiB
C#
Raw Normal View History

2026-08-06 07:55:48 -04:00
using UnityEngine;
2026-08-12 00:52:57 -04:00
public class HorizontalLaser : BarBase
2026-08-06 07:55:48 -04:00
{
public GameObject horizontalLaserPrefab;
// 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-06 07:55:48 -04:00
}
// Update is called once per frame
void FixedUpdate()
{
if (canFire)
{
if (canFireLeft)
{
Vector3 leftSide = new Vector3(
bounds.min.x - (bounds.size.x / 2.0f),
bounds.center.y,
bounds.center.z
);
var left = Instantiate(horizontalLaserPrefab, leftSide, Quaternion.identity);
var leftLaserScript = left.GetComponent<HorizontalLaser>();
leftLaserScript.canFireRight = false;
Physics2D.IgnoreCollision(
left.GetComponent<Collider2D>(),
GetComponent<Collider2D>(),
true
);
}
if (canFireRight)
{
Vector3 rightSide = new Vector3(
bounds.max.x + (bounds.size.x / 2.0f),
bounds.center.y,
bounds.center.z
);
var right = Instantiate(horizontalLaserPrefab, rightSide, Quaternion.identity);
var rightLaserScript = right.GetComponent<HorizontalLaser>();
rightLaserScript.canFireLeft = false;
Physics2D.IgnoreCollision(
right.GetComponent<Collider2D>(),
GetComponent<Collider2D>(),
true
);
}
canFire = false;
}
}
}