Static Types Pt. 2- C# Skill in Unity: 3

Objective: using static type to create utility helper class.

Photo by Halacious on Unsplash

Static type can also be very helpful by using it to create a utility helper. As static type can be called from any class, it can hold some methods to be called during the game.

Position adjuster

Let’s create a helper that would readjust the position of a gameobject.
Create a new script and set this script as a static class.

Then create a method with passing in a gameobject, and readjust the position of this gameobject to a fixed position.

As this method, you can imagine that sometimes you might need to set something back to a fixed position during the game and you have not set the reference, or it can be a reset system when you want to readjust it.

Now our method is ready, let’s call it from another script.

Using utility helper

Create another script and assign it to an object in game.

Then we can call the ReadjustPosition() method in Player script.

Now we can test it in the Play mode.

As you can see it is so easy to call a method from a static class.
And that is how to create a utility helper by using static class.

--

--

--

A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Disconnect Data Processing in OutSystems

Memory Managers — Part 0

Free upgrade to Windows 10 is still is available from Microsoft

What to write in your Code Journal | Code Journaling pt 3 of 4

Step-by-step Guide on How to Effectively Build a Structure for GitHub Projects and Create…

Internship Experience at Oasis Infobyte (https://oasisinfobyte.in/)

Scale your PyTorch code with LightningLite

It’s Official!

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

The Escape Button is a Feature

Delegate, Event, and Action

Custom Dynamic Ambient Systems

Unity Dev: From Prototype to Work of Art