#basically need to explain this line by line
1 messages · Page 1 of 1 (latest)
public static public makes it accessible from other scripts, static makes it so you can directly get it with myClass.myVariable, Action is the type, OnTargetHit is the name
OnTargetHit?.Invoke(); i think this checks if its null with the ? if its not then it invokes the action
I've said Action is an interface for any method which has no return and no input parameters, is that ok?
Action is not an interface, atleast not in the literal form
Score is a property, the variable itself is static, but you can only set it privately in this script
Target.OnTargetHit just subscribes and unsubscribes from the Action
ahhh, that makes a lot more sense
wait so is OnTargetHit? basically a bool?
its an Action
so would I even need that line of code, since when the object gets hit it should immediately invoke the action anyway
so it shouldn't have to check if it's null
just out of curiosity how would I actually get it work without the null check?
You could just remove it
But then you risk getting null
u mean the "?"
Yes but why do you want to remove it?
It doesn't hurt to have it there 😛
so if let's say if I was creating a timer, I'd have to make sure the score isn't incremented after the timer which I can do by unsubscribing from the action right?
i think that's correctly worded
yeah, so I won't be invoking this particular action to increment the score
once it's unsubscribed
correct?
Correct
ye
The method with Invoke would get called, but since you unsubbed the other method it would not increment
ah, I guess it works that way for now
but I appreciate it y'all 🙏 thanks so much for ur time
Np, good luck!