Giant Rotating Laser Part 1

Every boss needs a special attack

Tristan Engel
1 min readJul 27, 2021

In this article we start working on a special attack for our boss. A giant rotating laser that will damage the player.

To not make the laser instant kill the player we created a damage delay after each time the laser damaged the player. For testing purposes we also added 1.5f delay in Start().

Note we are using OnTriggerStay2D. We wouldn’t want to player to be able to enter the laser and stay in it and only getting damaged once.

[SerializeField] private float _speed = 15f;

private float _damageInterval = 0.5f;
private float _nextDamage = 1.5f;

private void Start()
{
_nextDamage = 1.5f + Time.time;
}

void Update()
{
transform.Rotate(Vector3.forward * (_speed * Time.deltaTime));
}

private void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "Player" && _nextDamage < Time.time)
{
_nextDamage = Time.time + _damageInterval;

Player player = other.GetComponent<Player>();
player.Damage();
}
}

--

--

Tristan Engel

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.