I’m trying to make a character class that contains all you need for a humanoid character because a prefab is just not working through different scenes.
I get the error: You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
I guess I want to know how to script character creation instead of using prefabs and having to set everything in every prefab. If my question is unclear please let me know.
here is an example of creating a character:
private List<HumanCharacter> _characters = new List<HumanCharacter>();
And here is an example of the class:
public class HumanCharacter : MonoBehaviour
{
public Transform transform;
private AnimationClip[] _animations; //set in Unity, the animations each character has
private GameObject _myself;
private HumanCharacter() { } //DVC Not Allowed
//EVC
public HumanCharacter(GameObject prefab, Vector3 position, Quaternion rotation, AnimationClip[] Animations)
{
_myself = (GameObject)Instantiate(prefab, position, rotation);
_animations = Animations;
this.transform = _myself.transform;
if( !_myself.GetComponent("Animation").ToString().Equals("Animation") )
_myself.AddComponent("Animation");
AddAnimations();
}
…