- Home /
2D toolkit object instance error
Hello again people out there, I'm having an error scripting with the 2d toolkit that eludes me (possibly it's just a petty thing 4 you guys but it's getting on my nerves here).
Here's my script:
using System.Collections;
public class PlayerWalkScript : MonoBehaviour {
private bool Idle_Player = true;
private bool Walking_Player =false;
private bool Facing_Left = false;
private float Movement_Speed = .25f;
private tk2dAnimatedSprite Player;
private void Awake()
{
Player = GetComponent<tk2dAnimatedSprite>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.RightArrow)){
if (!Player.IsPlaying("Walk")) {
Player.Play("Walk");
Walking_Player = true;
Idle_Player = false;
}
}
if (Input.GetKey(KeyCode.None)){
if (!Player.IsPlaying("Idle")) {
Player.Play("Idle");
Walking_Player = false;
Idle_Player = true;
}
}
}
}
The error is "NullReferenceException: Object reference not set to an instance of an object" in line 26, what I don't get is that as far as I know "Jacob" was created as an object already and when I type "Player.IsPlaying" or "Player.Playing" the command I want it autocompletes it, meaning it exist within "Player" but doesn't take the argument even thought it specifically asks for a string
where is Player_Jacob variable declared?
Walking_Jacob and Idle_Jacob too for that matter?
Are you sure your "tk2dAnimatedSprite"-component was found in the awake?
Which tk2d version are you using? I believe tk2dAnimatedSprite was deprecated in favor of tk2dSpriteAnimator. Are you sure you added a null check in Awake for the Player variable?
Your answer
Follow this Question
Related Questions
C# Null Reference Exception in Custom Function 1 Answer
Working Reference Still Throwing Null Reference Error 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
C# Need Help Finding Where Null Reference Exception Is 2 Answers
Why! I dont get it!NullReferenceException: Object reference not set to an instance of an object 1 Answer