Creating a negative pickup in Unity

  • In order to do it, have a powerup sprite in the project, attach relative collider and rigidbody components to the sprite by bringing the sprite into the project.
  • Please keep the “Is Trigger” option ticket so that it behaves like a powerup and the “Gravity” scale to 0 so that the powerup script can provide a controlled movement.
  • Then, do not forget to add the powerup script component with its’ required parameters.
Unity
  • Declare a bool variable in the player script.
private bool LaserDamagerCollected = false;
  • Go to the fire method and add a condition check with this variable.
C#
  • Create a method to change this variable value to true and call the method from the powerup script.
C#
C#
  • Before making it, a good part is to have a graphical way that makes the player aware of the unfortunate collection.
  • So, create a text element in the canvas and set it as per choice with an empty text. After that, get a reference to it in the player script.
Unity
[SerializeField]
private Text _laserShockText;
  • Create a coroutine that counts for 5 seconds before turning the if condition to false again. Meanwhile, the text shall keep displaying a message with a countdown.
C#
  • Lastly, call this coroutine in the method that was created prior.
C#

--

--

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