Hi, I’m having a problem with the Scripting Gravity [2/8] tutorial:
I get the following error in the console:
NullReferenceException: Object reference not set to an instance of an object
PhysicsObject.Movement (Vector2 move) (at Assets/PhysicsObject.cs:40)
PhysicsObject.FixedUpdate () (at Assets/PhysicsObject.cs:35)
I can’t see how my code differs from the example:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PhysicsObject : MonoBehaviour {
public float gravityModifier = 1f;
protected Rigidbody2D rb2d;
protected Vector2 velocity;
void onEnable()
{
rb2d = GetComponent<Rigidbody2D> ();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
velocity += gravityModifier * Physics2D.gravity * Time.deltaTime;
Vector2 deltaPosition = velocity * Time.deltaTime;
Vector2 move = Vector2.up * deltaPosition.y;
Movement (move);
}
void Movement(Vector2 move)
{
rb2d.position = rb2d.position + move;
}
}
Using Unity 2017.1.0f3 personal.