C# Statics in Unity! - Intermediate Scripting Tutorial

preview_player
Показать описание
Watch this video in context on Unity Learn:

Statics are methods, variables, classes that aren't instanced. This means that methods and variables declared as static will belong to the class specifically and will be shared by all objects of the class. Classes declared as static will not be able to be instantiated. In this video you will learn how to create and work with statics in Unity.
Рекомендации по теме
Комментарии
Автор

"Static methods are methods that belong to the class and not specific objects of the class" I think I understand now, thanks!!

WanderyenErin
Автор

Why don't these video's have more views? They are really good.

thedude
Автор

Great explanation. Really like the short and compact format of those tutorials!

victoraurelius
Автор

Up until this moment, I thought "static class" referred to my Grade 9 Homeform - when they all forgot to use fabric softener. Grade 9 - the *best* three years of my life!!!

studioshitaketakashita
Автор

I finally have come to understand this concept. Thank you.

Peak_Stone
Автор

When I declare a class as static, do I have to also use the "static" keyword to declare each member? Also, can I declare a static struct? Or is it only classes and their members?

smsmsm
Автор

Is saying "objects" of a class some C# way of saying "instances"?

OMNI_INFINITY
Автор

Really great video, thank you
So, now I know that static is something that is fixed

段国威-vm
Автор

If you make a static class, do you still need to make the methods inside it static to access them?

kristianthaler
Автор

Do static method and classes persist during different game section like playerprefs?

tochukwuunamma
Автор

How can I make a static gameObject variable and show it in the inspector in order to assing the gameobject that I want?

ZefiDev
Автор

Really great explanations on this channel! What I'm still confused about is how my project knows where the static method is defined if I'm not referencing an object? Do I just need the class definition somewhere in my assets for this to work?

Nova
Автор

Seems he was supposed to say "instance" of a class.

OMNI_INFINITY
Автор

Men I love u thank u so much. Really thanks

gabrieleduardobrambilla
Автор

Doing the first one gives a warning and crashes the game

fidelramen
Автор

Let me save you some 3 mins of your life

If you don't like tying "Class Variable = new Class()" everytime you wanna access a variable from other class, then add a *static* keyword on that variable you're trying to access from the other class. Example:
//WITHOUT STATIC
class Firstclass {
int x = 69;
}
class Secondclass {
Firstclass firstvariable= new Firstclass();
Debug.Log(firstvariable.x);
}

//WITH STATIC
class Firstclass {
static int x = 69;
}
class Secondclass {
Debug.Log(Firstclass.x);
}

You can't instantiate an object of a class with static variable because a static variable is supposed to be unique and original for that class only meaning you can't make a clone or fresh copy out of it.

piztech