Hello!
I would need some help witht he following:
NullReferenceException: Object reference not set to an instance of an object
PlayerController.Update () (at Assets/Player/Scripts/PlayerController.cs:28)
My unity keep telling me this and i guess. that Unity wants a value on something but i dont understand what and how to do that. I am a beginner at scripting and havent fugured out all the know hows yet so please awnser like i was an idiot
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PlayerPhysics))]
public class PlayerController : MonoBehaviour {
// Handling
public float speed = 8;
public float acceleration = 12;
private float currentSpeed;
private float targetSpeed;
private Vector2 amountToMove;
private PlayerPhysics PlayerPhysics;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
targetSpeed = Input.GetAxisRaw("Horizontal") * speed;
currentSpeed = IncrementTowards(currentSpeed, targetSpeed,acceleration);
amountToMove = new Vector2(currentSpeed,0);
PlayerPhysics.Move(amountToMove * Time.deltaTime);
}
// Increase n towards target by speed
private float IncrementTowards(float n, float target, float a) {
if(n == target) {
return n;
}
else {
float dir = Mathf.Sign(target - n); // must n be incresed or decreased to get closer to target
n += a * Time.deltaTime * dir;
return(dir == Mathf.Sign(target-n))? n: target; //If n has now passed target then return target, otherwise return n
}
}
}
Would apriciate help very much, thank you!