I'm trying to instantiate a user-controlled avatar (in this case a simple cube from a prefab).
There must be something wrong with the way my prefab is set up, because my program is working as intended when I drop the necessary scripts onto an existing GameObject cube.
When I run my program once, it works fine with all the scripts triggering as they should. I stop and run again and Unity crashes to desktop.
Here's the code that I think is suspect. Being a novice C# and Unity user, I wouldn't be surprised if I'm doing it wrong, so any help is greatly appreciated.
Thanks in advance.
public class InstantiatePlayer : MonoBehaviour {
public new Transform PlayerBlock;
void Start () {
//place movement and behavior scripts onto transform
PlayerBlock.gameObject.AddComponent("PlayerMove");
PlayerBlock.gameObject.AddComponent("ColorChangeBehavior");
//put a new moveable cube with behavior script on it at origin point
Instantiate(PlayerBlock, new Vector3(0.0f,0.0f,0.0f), Quaternion.identity);
}
}