For this lesson we made modifications to the Enemy.cs script so that, on death, they would deposit coins into our bank.
I’m very new to coding and the actual roles that “Bank bank” and " bank = FindObjectOfType();" play are a little unclear to me.
Am I correct in thinking that “Bank” is a type of variable and “bank” is the name of the variable? Why is “Bank” the type of variable we are using? Is it because we are referencing the Bank.cs script we wrote previously or is there another reason for the name, or can we name these whatever makes sense for us? For instance, could we have named our type and variable PiggyBank piggyBank?
Secondly, what is " bank = FindObjectOfType(); " doing for the computer? We’ve already told it what type of variable “bank” is, is it locating the Bank.cs script or something else?
Any help is greatly appreciated!
Here’s the bits of relevant code from our Enemy.cs script:
public class Enemy : MonoBehaviour
{
Bank bank;
void Start()
{
bank = FindObjectOfType<Bank>();
}
public void RewardGold()
{
if(bank == null) { return; }
bank.Deposit(goldReward);
}
}