#thread
1 messages · Page 1 of 1 (latest)
What script has the error, and what object has this script
"Grenade" has the error, and the prefab "Grenade Variant" has this script.
(the grenade script.)
Okay. And does Grenade Variant have a GrenadeSound script
no
Then this line:
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?
yes
And "GrenadeSound (Game Object)" is the object that "GrenadeSound" is on.
So, if you say "Please give me the GrenadeSound component of the Grenade Variant object", what do you think happens
null
Exactly
what am I supposed to do then?
¯_(ツ)_/¯
What GrenadeSound do you want
Should this object have one?
I mean it's outside of a prefab.
no
Only you can answer
because it gets destroyed.
So, which one do you want
Which GrenadeSound do you want to access
Which GrenadeSound do you want to access
That's what I mean
This is a component
that could be on any object
Which one
this game object.
Okay, so, now you need your Grenade script to have a reference to this object
A few basic ways to get references in Unity.
Directly-
GetComponent 0:38
/GetComponentInChildren
/GetComponentInParent
Public Variable- 3:00
Find- 5:01
Find 5:39 (by name)
FindWithTag 6:14 (by tag)
FindObjectOfType 6:51 (by component)
Interaction- 7:15
OnCollisionEnter
/OnTriggerEnter
There are many ways to do this. Just skip the one you can't do (dragging it in)