- Home /
Unity 5 Adding a script component to another object upon Enter
I have a script that gives a script to another object depending on certain variables within a Script called NetworkConnectScript. I need to access an array within that script and use the data within that array to add a specific script to an object. I had no problems until I updated to Unity 5 when I found out that this doesn't work with the current API (I made back ups if I can't solve this issue). Is there a way to add a script using a string with Unity 5? Here's the code below.
//Access NetworkConnectScript
NetworkConnect_Script net = networkConnectObject.GetComponent();
//Enter is defined within OnTriggerEnter(Collider Enter) & networkViewOwnerInt is Network.Player
//Access the entered gameobject and assign it a script from the networkPlayerClasses array Enter.gameObject.AddComponent(net.networkPlayerClasses[networkViewOwnerInt]+ "_Script");
I will gladly answer any questions you may have about my question.