Hi,
I have created an animation that works with the animator. On the animator there is a boolean, if the bool gets to true the animation “jump” will play.
My problem here is that the player only plays the jump animation but doesn’t move and I get this error message:
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.AnimationStateMachine.TransitionEditionContext.BuildNames () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/TransitionEditionContext.cs:44)
UnityEditor.Graphs.AnimationStateMachine.TransitionEditionContext..ctor (UnityEditor.Animations.AnimatorTransitionBase aTransition, UnityEditor.Animations.AnimatorState aSourceState, UnityEditor.Animations.AnimatorStateMachine aSourceStateMachine, UnityEditor.Animations.AnimatorStateMachine aOwnerStateMachine) (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/TransitionEditionContext.cs:28)
UnityEditor.Graphs.AnimationStateMachine.AnimatorTransitionInspectorBase.ComputeTransitionContexts () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorTransitionInspectorBase.cs:125)
UnityEditor.Graphs.AnimationStateMachine.AnimatorTransitionInspectorBase.OnEnable () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorTransitionInspectorBase.cs:87)
UnityEditor.Graphs.AnimationStateMachine.AnimatorStateTransitionInspector.OnEnable () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorStateTransitionInspector.cs:55)
Here is a video:
Here is the script that I use:
using UnityEngine;
using System.Collections;
public class PlayerControl3 : MonoBehaviour {
private float perc = 1;
private Vector3 startPos;
private Vector3 endPos;
public Animator anim;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetButtonDown ("up") || Input.GetButtonDown ("down") || Input.GetButtonDown ("left") || Input.GetButtonDown ("right"))
{
anim.SetBool("Jump",true);
}
else
{
anim.SetBool("Jump",false);
}
startPos = gameObject.transform.position;
if(Input.GetButtonDown("right") && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
}
if(Input.GetButtonDown("left") && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
}
if(Input.GetButtonDown("up") && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
}
if(Input.GetButtonDown("down") && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x , transform.position.y, transform.position.z - 1);
}
gameObject.transform.position = Vector3.Lerp (startPos, endPos, perc);
}
}