- Home /
_player = new Player(); *CRASH!*
So I have a Player class. Here's the gist of it:
using UnityEngine; using System.Collections;
public class Player { //Left Stick private string _horizontalAxis; public string horizontalAxis { get { return _horizontalAxis; } set {_horizontalAxis = value; } }
public Player() {
_horizontalAxis = "Horizontal";
_verticalAxis = "Vertical";
}
}
In my character motor script, I have this:
private Player _player;
void Awake() {
_player = new Player();
}
For some reason, Unity crashes when do this. I have narrowed it down to this group, and can't find the problem. What might I be doing wrong?
Answer by Eric5h5 · Dec 03, 2010 at 11:45 PM
Works fine here, as long as the reference to _verticalAxis is removed of course, since that's not included in your code.
Answer by fireDude67 · Dec 03, 2010 at 11:41 PM
All Unity Scripts must inherit from MonoBehaviour
if you want to add it to a GameObject
There's no particular reason to add that script (the first one) to a GameObject.
The op never said that they were trying to add an instance of the Player class to a GameObject.
Oh wait, I see. It seems whenever I tried to reference _player, it didn't work for some reason. I thought I'd commented that line out, but I guess I didn't for that test...