#need help with names and arrays

1 messages · Page 1 of 1 (latest)

thin bobcat
#

if anyone answers pls ping me

misty yew
#

@thin bobcat your logic isn't correct here. You have it written so that if ANY name in the list does not match collider's name, colliding becomes true

#

the moment you have two or more unique entries, colliding will always be true

thin bobcat
#

ok that makes sense

#

also I'm getting a NullReferenceException

#

oh actually that's what I wanted

#

@misty yew I want it to be that if his feet are touching anything, as long as it isn't the legs that they will be able to jump

misty yew
#

you can fix your loop logic to make it work. Your loop should check if any excludable matches other.name, and if it does return. Then after the loop, colliding = true

thin bobcat
#

I'm pretty sure the loop is working I just don't know why I'm getting the NullReferenceException error

#

the excludables are the ones that it shouldn't set colliding to true when it's touching

misty yew
#

rightFoot or leftFoot is probably null

#

yes but that logic is broken as-is like I mentioned, the moment you have two entries, it's impossible for one of them not to trigger your condition

thin bobcat
#

even if it's touching the leg because it will always be touching the leg, it is still supposed to count as colliding

#

oh my bad I see what you mean

#

do I have it set up right to add rightLeg.name to the rFoot.excludables array and same with the left or is there a problem with that?

#

I've never really worked with arrays in unity before

misty yew
#

no, but it'll throw index out of range instead of nullref

#

I suggest you use a List instead

#

List<string> as the type
then to add it's simply rFoot.excludables.Add(rightLeg.name)

thin bobcat
#

ok thx I'll try that and let you know if it works

#

with a list, do I use count instead of length?

misty yew
#

yeah

thin bobcat
#

hmm, I don't know if it's working because it's still giving that nullreferenceerror

misty yew
#

at what line?

thin bobcat
#

69 17 and 29

#

rFoot.excludables.Add(rightLeg.name);
for (int i = 0; i < excludables.Count; i++)
if (excludables.Count == 0)

misty yew
#

did you configure excludables in the inspector? that shouldn't be null

#

rFoot or rightLeg are probably the issue

#

oh that's probably what it is, you aren't configuring with serialized values at all

#

use this to initialize excludables: public List<string> excludables = new List<string>();