To call a Prefab object in the game when one action happens i’m using the following script:
public GameObject obj;
obj = Resources.Load(“ppoder”) as GameObject;
Instantiate(obj, transform.position, transform.rotation);
//Error message is: Failed to load component (MonoBehaviour)! Removing It!
And when i add this line of code, the change on the message is:
obj.AddComponent(“PMagia”);
//Error message is: Component MonoBehaviour could not be loaded when loading game object. Cleaning Up!
Component MonoBehaviour could not be loaded when loading game object. Cleaning Up!
UnityEditor.DockArea:OnGUI()
So i want to know if im using the right way to put a Prefab object in the game??
Any solution?
Simply use obj = Resources.Load(“ppoder”) as GameObject; and that’s it. Make sure your prefab is named “ppoder.prefab”. Then alter the obj gameObject like any other object: obj.transform.position = … (e.g.)
After that obj.AddComponent(“PMagia”); should work IF you have a script with that name (PMagia.cs).
I have it all working since the first post, but the Unity3D keeps telling me some messages… and when i restart it, or do another project with the same scripts he works fine till i use this line:
I think i found the error, i tried to put the SCRIPT PMagia in the Prefab when i created him, and the messages stoped… I guess i were doing something wrong trying to add a new Script in the Prefab, but to my project if the Prefab starts with the script it doesnt matter… Thanks for your help AxeIF.