Hello everyone, I have a problem with NullReferenceException, but this error does not affect the compilation of the code, my player still moves correctly. But annoying error messages appear in the console. Here’s the code:
public class PlayerPlatformerController : PhysicsObject {
public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;
private SpriteRenderer spriteRenderer;
private Animator animator;
public Joystick Joystick;
// Use this for initialization
protected override void ComputeVelocity()
{
Vector2 move = Vector2.zero;
if (Joystick.Horizontal > .5f)
{
move.x = Joystick.Horizontal;
} else if (Joystick.Horizontal < -.5f)
move.x = Joystick.Horizontal;
else move.x =0;
if (Joystick.Vertical > .8f && grounded) {
velocity.y = jumpTakeOffSpeed;
} else if ( Joystick.Vertical < .8f && grounded == false)
{
if (velocity.y > 0) {
velocity.y = velocity.y * 0.5f;
}
}
targetVelocity = move * maxSpeed;
}
}
Here is the error message: