#thread

1 messages · Page 1 of 1 (latest)

obtuse grove
tired spindle
#

What script has the error, and what object has this script

obtuse grove
#

"Grenade" has the error, and the prefab "Grenade Variant" has this script.

#

(the grenade script.)

tired spindle
#

Okay. And does Grenade Variant have a GrenadeSound script

obtuse grove
#

no

tired spindle
#

Then this line:

obtuse grove
#

it gets it via getcomponent.

#

or it should do.

tired spindle
obtuse grove
#

yes

#

I'm trying to get the script.

tired spindle
#

This line is saying "Get the GrenadeSound component from the object I am on, and store it in a variable named grenadeSound"

#

Now, Grenade Variant is the object this script is on

#

Correct?

obtuse grove
#

And "GrenadeSound (Game Object)" is the object that "GrenadeSound" is on.

tired spindle
# obtuse grove yes

So, if you say "Please give me the GrenadeSound component of the Grenade Variant object", what do you think happens

obtuse grove
#

null

tired spindle
#

Exactly

obtuse grove
#

what am I supposed to do then?

tired spindle
#

What GrenadeSound do you want

#

Should this object have one?

obtuse grove
#

I mean it's outside of a prefab.

obtuse grove
tired spindle
#

Only you can answer

obtuse grove
#

because it gets destroyed.

tired spindle
obtuse grove
#

I wanna play the sound.

#

not play it and then destroy it lol.

tired spindle
#

Which GrenadeSound do you want to access

obtuse grove
#

its source?

#

or what

#

do you mean?

tired spindle
#

Which GrenadeSound do you want to access

#

That's what I mean

#

This is a component

#

that could be on any object

#

Which one

obtuse grove
#

this game object.

tired spindle
obtuse grove
#

which isn't possible via the inspector.

#

so how

#

?

tired spindle
#

There are many ways to do this. Just skip the one you can't do (dragging it in)

obtuse grove
#

okay thanks.

#

I have to go so yeah.