Make efficient use of Prefabs by controlling instances’ strength

Samarth Dhroov
2 min readMay 5, 2021

--

Control

Note: Before you proceed to this article, I recommend reading my previous article since this is extending it for a feature only.

Everything shall happen in a controlled manner to maintain harmony. It is no different when it comes to games.

When we multiply prefabs with keyboard input actions, we overload the memory consumption as well as power consumption. Therefore, we better restrict it to a limit just like how we restrict drivers on roads with their vehicles.

Let's head to Visual Studio to write some code.

  • First, we are going to declare two float variables. One that is going to mimic time and the other is going to work as an addition agent.
C#
  • Second, we’d have to use the Time.time property to gauge how long the game has been running and compare it to the _canfire value.
  • If the condition is false, there will be a delay of 0.5 seconds before the next round of firing. If not, the firing will continue and the firerate amount will be added to the _canfire variable with the current time.
C#

With this implementation, you shall see a much-controlled version of firing mechanics in your game.

Unity

Thank you very much

--

--

No responses yet