I have a button to fire and Fire() method which includes functions related to firing. I assign GameObjects in Awake Method so it wouldn’t have to assign them each time i click on button.
But button is not taking functions into consideration which are outside of Fire() method. Any suggestions ? Thanks…
What do you mean by “taking functions into consideration”? Your description of the situation is pretty vague. Maybe share some screenshots/descriptions of your setup, as well as whatever code is relevant, e.g. "Here’s the inspector for Object A with the OnClick handler registered to this object which… etc.
I mean by saying “taking functions into consideration” is that the functions which are exclusive of Fire() method is not being considered when i click on button. It only considers inside of Fire() method… I get errors saying “Object reference not set to an instance of an object.”
Yes I understand that. Can you please paste the full error message including the numbers at the end as it contains more information such as the exact line number on which it occurs.
I can share but there’s no problem by assigning them. Errors occurs when i reference them from Awake() to Fire() method. Button wants all functions to be inside Fire() or it wouldn’t find them…
That’s your problem. You’ll want to have your button reference an actual object in the scene, not a prefab. I’m not even sure Awake gets called on the prefab itself, and if it does, it’s probably before your scene is even loaded.
I instantiate prefab as a new gameobject. I always use this method and the clone object works well in other cases. I will try to reference an alive object and see what happens. Thanks for helping…
it’s not the fire effect I’m talking about. I’m talking about the screenshot where your button OnClick listener is referencing the PlayerMovement object. Is that PlayerMovement object in the scene or is it a prefab?