Hello,
I'd like to set a variable on a script attached to a game object that is instantiated at runtime. How to do that? It's easy if I have the object at the scene and it's only one object, but I want to be able to set a script on a different object with the same FSM.
Example:
car1 - prefab with script name "car engine" with tag "car"
car2 - prefab with script name "car engine" with tag "car"
car3 - prefab with script name "car engine" with tag "car"
If I drag the "car engine" script from car1, which I put in the scene to an FSM called "car throttle" I can easily set the car throttle variable at run time for this car1.
But I want to access this car throttle variable to the other cars as well with single FSM in the scene.
So I want to do the following:
1. Find game object with tag "car".
2. Store it in a player-car game object.
3. Set car throttle variable in the player car game object in the script "car engine".
How to do point 3 at runtime, given that I can choose any car?
Thank you!