#basically need to explain this line by line

1 messages · Page 1 of 1 (latest)

quiet sinew
#

it makes sense in my head but dk how to explain it

#

the highlighted bits

molten grove
# quiet sinew

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

molten grove
# quiet sinew

OnTargetHit?.Invoke(); i think this checks if its null with the ? if its not then it invokes the action

quiet sinew
#

I've said Action is an interface for any method which has no return and no input parameters, is that ok?

peak haven
#

Action is not an interface, atleast not in the literal form

molten grove
# quiet sinew

Score is a property, the variable itself is static, but you can only set it privately in this script

molten grove
# quiet sinew

Target.OnTargetHit just subscribes and unsubscribes from the Action

quiet sinew
quiet sinew
molten grove
quiet sinew
#

so it shouldn't have to check if it's null

peak haven
#

It is fine to have the null check there

#

Just to be sure

#

This 🙂

quiet sinew
quiet sinew
#

oh

peak haven
#

But then you risk getting null

quiet sinew
#

u mean the "?"

peak haven
quiet sinew
#

not for this object

#

but was just curious

#

i need to deliberately create errors

peak haven
#

It doesn't hurt to have it there 😛

quiet sinew
#

for my project cuz its expected of me

#

xd

quiet sinew
#

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?

quiet sinew
#

ye

peak haven
#

The method with Invoke would get called, but since you unsubbed the other method it would not increment

quiet sinew
#

but I appreciate it y'all 🙏 thanks so much for ur time

peak haven
#

Np, good luck!