There is a slight difference between (cast) and “as”
When you cast like this
Weapon weapon = (Weapon)Resources.Load(defaultWeaponName);
and the resource being loaded does not exist or have a Weapon
component, C# will throw an exception.
But when you cast like this
Weapon weapon = Resources.Load(defaultWeaponName) as Weapon;
C# will not throw an exception, but your weapon
variable will be null
Using this
Weapon weapon = Resources.Load<Weapon>(defaultWeaponName);
Will also return null
if the resource cannot be found, or if there is no Weapon
component on it.
According to the Unity documentation, Unity does the conversion for you and judging by the result, it probably uses “as”.
In general, the usage is up to you. If you want an exception, use (cast). If you expect possible nulls, use “as”.
Note that structs cannot be cast using “as” because they cannot be null, but in the case mentioned above, you will not be casting structs.