- Home /
Question by
Bashie · May 04, 2016 at 05:29 AM ·
object reference
Script object reference not set
HI All,
So i am currently going through tutorials for Unity. But i have come to a head scratching moment. I am following a tutorial guide by Sebastian Lague.
And in my current script that I have followed so far is:
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (Controller2D))]
public class Player : MonoBehaviour {
float moveSpeed = 6;
float gravity = -20;
Vector3 velocity;
Controller2D controller;
void start() {
controller = GetComponent<Controller2D> ();
}
void Update() {
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
velocity.x = input.x * moveSpeed;
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
Now i get an error here - Object reference not set to an instance of an object.
This bothered me so much that i went and took a look at the source code Sebastian provided, and in my eyes its the same. Link to the code Sebastian provided :
https://github.com/SebLague/2DPlatformer-Tutorial/blob/master/Episode%2002/Player.cs
My question is. What have I done wrong ? Out of curiosity i copied Sebastian code and it worked fine, I just cant seem to find the error in question.
Comment
Yup that would do it. I'll see myself out.
Thank you :)