Laser defender, new ship class, lightning

I have a lightning that is animated and it’s as big as a screen, it shoots from buttom-up. I want to spawn lightning on mouse hold and I want it to loop animation until I release mouse. And I want it to make damage to everything that flies in or through it. And if something is within collider, I want it to keep causing damage every let’s say .2 seconds. Can anyone help me out with this.

So one way could be :

  • Instantiate the lightning sprite on Input.GetMouseButtonDown and destroy it on Input.GetMouseButtonUp , Mouse position can be had using Input.mousePosition
  • The lightning sprite would have its collider set as a trigger so that while its in the scene (between mouse up and down) anything that collides with it would trigger that if that thing collided with with lightning which could be checked using tags for example the gameobject could deduct some points from itself.
  • The part about deducting points continuously every 2 secs etc will be a bit more complex though you could check out OnTriggerStay2D which sould be useful for this i think.
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms