C# Static Members And Singletons in Unity

Published: 13 November 2024
on channel: XR Terra Class
81
0

This video explains static members, and how they can be used to create Singleton scripts in your project. Singleton scripts have the advantage of being referenced without needing a scene reference, which helps us a lot when it comes to managing Prefabs in our scene.

XRTerra Links:
Programs and Courses: http://www.xrterra.com/programs
Newsletter Signup: https://www.xrterra.com/mailing-list-...

Creating and Editing Prefabs:    • Creating And Editing Prefabs in Unity  
Instantiating Prefabs:    • Instantiating Prefabs in Unity  

00:00 Explaining static members
01:33 Instantiated moving cube exercise
02:26 Move Forwards script
03:32 Instance specific variable values
03:54 Making the cube a prefab
04:15 Instantiate on loop script
05:44 Inspector setup for instantiation
06:12 Randomizing cube speed
07:25 Making speed a static property
07:48 Setting a static variable
08:27 Testing out static speed
09:05 Explaining singleton scripts
10:19 Usefulness with prefabs
11:16 How to define a class as a singleton
12:38 Referencing a singleton
13:14 Explaining our singleton exercise
14:47 Creating a public MoveUp() function
15:24 Turning our script into a singleton
16:36 Cubes destroy after random time
18:10 Calling MoveUp() before destruction
18:45 Testing out our exercise

Instructor: Gregory Osborne


Watch video C# Static Members And Singletons in Unity online without registration, duration hours minute second in high quality. This video was added by user XR Terra Class 13 November 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 81 once and liked it 0 people.