Hello, I’ve spended the last three hours understanding how to attach a script to an GameObject but still - 0 success.
All what I want to do is really simple, I just want to add a script to gameobject without doing it by unity, just with code.
Here’s what I’ve got:
// Main Objects
public GameObject m_Player;
// Use this for initialization
void Start () {
// Player GameObject Init
m_Player = new GameObject ("Player");
m_Player.AddComponent ("c_Player.cs");
m_Player.AddComponent ("CapsuleCollider");
}
But I’m getting this error:
Can't add component because class 'c_Player.cs' doesn't exist!
UnityEngine.GameObject:AddComponent(String)
c_Launcher:Start() (at Assets/Scripts/Player/c_Launcher.cs:12)
The file “c_Player.cs” exists and it’s located in my Assets>Scripts>Player folder. Any suggestions?