Hello, I’m a novice coder and don’t quite understand all the articulates of C#, so when I look at other people’s source code to learn from it some things I don’t quite understand.
The one I’m looking at in particular is [Dani’s LudumDare 45 vlog][1]
[Here is the source code for his “Actor” script I’m looking at][2]
I’m currently trying to make a 2D game which contains player’s and enemies and I understand that you can have one script with multiple declaring variables for that particular group of actors to save on coding.
On line 35 - 43 there’s a particular function that is called which I’m failing to understand the purpose of, here is a snippet of that particular code
protected virtual void Init() { }
private void Awake() {
ps = GetComponentInChildren<ParticleSystem>();
em = ps.emission;
rb = GetComponent<Rigidbody2D>();
Init();
sr = GetComponent<SpriteRenderer>();
dColor = sr.color;
}
An “Init” function is I assume, overwritten but there’s no parameters or code in the actual function and then is called in the “Awake” function. What is the purpose of this function? As well as what benefit is having the function be protected? Thanks in advanced
[1]: Making a Game in 2 DAYS! - YouTube
[2]: LudumDare45/LD45/Player/Actor.cs at master · DaniDevy/LudumDare45 · GitHub