Here are the problems:
1)
NullReferenceException: Object reference not set to an instance of an object
PlayerController.Update () (at Assets/Scripts/PlayerController.cs:30)
2)
‘Timothy Clever’ AnimationEvent ‘Movement’ has no receiver! Are you missing a component?
Here is the actual script:
usingUnityEngine;
usingSystem.Collections;
[RequireComponent(typeof(PlayerPhysics))]
publicclassPlayerController : MonoBehaviour {
//PlayerHandling
publicfloatgravity = 20;
publicfloatspeed = 8;
publicfloatacceleration = 45;
publicfloatjumpHeight = 12;
privatefloatcurrentSpeed;
privatefloattargetSpeed;
privateVector2amountToMove;
privatePlayerPhysicsplayerPhysics;
voidStart () {
playerPhysics = GetComponent();
}
voidUpdate () {
Movement();
}
voidMovement()
{
if(Input.GetKey (KeyCode.D))
{
transform.Translate(Vector2.right * 2f * Time.deltaTime);
transform.eulerAngles = newVector2(0, 0);
}
if(Input.GetKey (KeyCode.A))
{
transform.Translate(Vector2.right * 2f * Time.deltaTime);
transform.eulerAngles = newVector2(0, 180);
}
//Input
targetSpeed = Input.GetAxisRaw(“Horizontal”) * speed;
currentSpeed = IncrementTowards(currentSpeed, targetSpeed,acceleration);
if (playerPhysics.grounded) {
amountToMove.y = 0;
//Jump
if (Input.GetButtonDown(“Jump”)) {
amountToMove.y = jumpHeight;
}
}
amountToMove.x = currentSpeed;
amountToMove.y -= gravity * Time.deltaTime;
playerPhysics.Move(amountToMove * Time.deltaTime);
}
//Increasentowardstargetbyspeed
privatefloatIncrementTowards(floatn, floattarget, floata) {
if (n == target) {
returnn;
}
else {
floatdir = Mathf.Sign(target - n); //mustnbeincreasedordecreasedtogetclosertotarget
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign(target-n))? n: target; //ifnhasnowpassedtargetthenreturntarget, otherwisereturnn
}
}
}