Alex Mahan has become pretty normal for successful people on the internet these days. It's not about talent, it's about being starved enough for validation that you'll post Youtube videos every day and farm ads for a corporate leviathan that sees no problem with directing kids to videos about Mickey raping Minnie to death. The web is now run by people who, in my day, would have been operating shady online casinos that required you to click on ad banners to spin a virtual wheel of fortune.
But regarding his code and use of Unity, I'd like to speculate on it. It's hard to say for sure what he's actually doing just from looking at a decompiler but...
First of all, it appears he's running one script for all students. There's been a lot of talk about the code, his "if else" spaghetti versus switch cases, but I don't know if in 1,700+ pages this thread has discussed Unity's structure and why Alex has programmed Yandere Sim like this:
Unity is "object oriented", which for our understanding in this thread could be simplified to say all the code is actually dragged and dropped into objects in the game and executed while those objects are present. This is handy and easy to learn in a lot of ways, especially for creating things like a user interface where you can place a "button" object on screen and then program that button's behavior directly into the button. You tell the button "if you're clicked on, execute the following code", and it's easy to compartmentalize and understand for humans.
However, there's a pitfall here and I think Alex has fallen into it. It's that you can drag and drop the same code into different objects. Therefore, if you wanted to write code for three buttons, you could write a single script and drag it into all three buttons.
if (button == 1)
SceneManage.LoadScene("Giant Dong");
if (button == 2)
PlayFx(giantDongScream);
if (button == 3)
Application.Quit;
//There is a giant dong right behind you.
This isn't REALLY what object oriented coding is meant to do, but it's possible and it would put all the code in a single document so that when you're programming you're not juggling between a bunch of different tabs. You could just make a unique program interaction with all three buttons and it would be faster because you aren't re-using any code at all anyway - the if statements are only checking what button is being clicked.
This forum has thrown around the idea that a case switch would benefit Alex's code, which has been rebuffed by a few others. The answer lies in between, as many answers do. Case switches are actually faster, but they're limited to switching a specific variable. You define with:
switch (buttNumber)
{
default:
...
break;
case 1:
...
break;
case 2:
...
break;
}
This is great, and when you have a lot of them they're treated as a dictionary lookup, which is faster than making a unique evaluation of each case like you'd go through with an "if" statement. However, you can see you're locked in to needing to know what the case
is. It needs to be case 1, or case 2, or case "cabbages" or however you've defined the switch. It has to be that one thing. It doesn't work as conveniently if you need to check if, say, a particular character knows judo AND is also a student. It still can work, but then you'll start getting into nested statements again and it isn't necessarily saving computing time.
This is why more experienced programmers have been saying Alex needs to invest into inheritance, which structurally requires some planning. The simplest way to put it - and I know it's been explained before through video and elsewhere on the forum - is by imagining every student behaves exactly the same but has a unique reaction to a stabbing. You could call that reaction "Stabbing()". You'd have the parent code, which defines all the things all the students always do, and then a child class, which inherits from the parent. All you need to write is a unique Stabbing() class as an override in the child.
Now, in a really complicated game, you have many different types of students doing many different things, so using inheritance can become confusing if you don't know how it's organized. It's easy to imagine why Alex would become frustrated with another programmer who tried to refactor his code this way; it would make it to where Alex doesn't know where the code is anymore without parsing through a large density of information. It is what any reasonably complex game is going to need and it's more efficient, but you need to be familiar with the structure or else it can be like navigating a choose your own adventure book.
The inheritance concept is just an extension of what object oriented programming revolves around. Each object does its own thing, and if a set of things all behaves the same except for some specific variances, you still want to compartmentalize the code into the objects. That said, Alex
may be using inheritance already, albeit not very well. In his mind perhaps every character needs to check if they're a ninja, or a Russian, or a teacher, or an eggplant before they know what class to call. It's honestly difficult to say because programming is always an exciting, experimental stew of seeing what works and trying to program fail-safes in case your program behaves in a manner that is theoretically impossible. Everyone approaches the stew a little differently and there are no recipes that make exactly what you want, or else you wouldn't be programming it (because after all, if it were already written it wouldn't need to be written again).
Finally, all this said - as for animations? I personally hate how Unity handles animations. In an effort to be user friendly, it has its own node-based animation interface. Having a lot of unique animations can lead to strings pointed everywhere like a conspiracy board. You actually CAN call animations from script, but frankly using their system is an extra pain in the ass thrown on top of the normal agonizing tedium of animation.
In a nutshell, if Alex plans to change the characters at some point, he won't have the freedom to change the models themselves. He might be able to change the hair or the face, or some other superficial details, but if the models are changed someone will have to re-animate everything.