I’ve been looking around and I can’t find an answer. (Not that I looked every nook and cranny, but a little general search.)
Pretty much what I’m looking for is something like making a variable to hold s script, then calling it in an Update method.
I want this for modular-bility. Like on collide, it can sometimes explode or get vaporized.
http://answers.unity3d.com/questions/24814/how-do-you-load-a-script-in-a-script
Also asked in the UnityAnswers, so just answer there, or answer here, and I’ll add it to the answer there so it’s easily accessible.
If you just want to call functions from another script, then just hold a reference to the script and call those functions. Sounds like you’re thinking about things backwards here.
Then call a different function depending on which of these actions you want. You don’t really need entirely different scripts loaded at run-time to do this, but if you do then just attach the two different scripts to the object (or explosion manager, or whatever) and call functions from them.
Yea, that’s the word for it. How to call a script inside a script.
Is there a way to make a variable to store an instance to a script? Then drag a script to it using the the UI, or not even.
Really, I’m just looking for a way to call a script and if possible, store that script in a variable so it can be manipulated easier.
EDIT: Ah, nevermind, after finding out out the word for it was calling (I can’t believe I forgot that, since I did take some programming courses a good while back) it was easy to find.
Coolz.
I’ve found that there is a way to set a variable of a specific script, for instance the HeadLookController, as a public property in the script attached to your object. Then using the little arrow on the right side of the property to trigger the drop down menu, it should display all game objects currently in the Hierarchy (not Project, but actively in Hierarchy) that have that type of script component attached. However if you’re trying to address a script that is a component of a prefab that is in your Project that you are dynamically instantiating on runtime, that’s a different issue entirely. In that case I’ve had to use GameObject.Find within the Start() method of my script to find the appropriate object instance.
Hope that helps.