Giant Rotating Laser Part 1

Every boss needs a special attack

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();
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tristan Engel

Tristan Engel

18 Followers

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