Error: An object reference is required to access non-static member, help?
I'm using Unity 5 to make a simple 2D game following a tutorial and I keep getting this error:
I'm trying to add a jump script to my player and I think it's to do with the fact the tutorial is using unity 4, so there might be script changes. The jump script is referencing a collision state script. Here are my two scripts:
Collision script:
using UnityEngine; using System.Collections;
public class ColissionState : MonoBehaviour {
public LayerMask collisionLayer;
public bool standing;
public Vector2 bottomPosition = Vector2.zero;
public float collisionRadius = 10f;
public Color debugCollisionColor = Color.red;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void FixedUpdate(){
var pos = bottomPosition;
pos.x += transform.position.x;
pos.y += transform.position.y;
standing = Physics2D.OverlapCircle(pos, collisionRadius, collisionLayer);
}
void OnDrawGizmos(){
Gizmos.color = debugCollisionColor;
var pos = bottomPosition;
pos.x += transform.position.x;
pos.y += transform.position.y;
Gizmos.DrawWireSphere (pos, collisionRadius);
}
jump script:
using UnityEngine; using System.Collections;
public class Jump : AbstractBehaviour {
public float jumpSpeed = 200f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
var canJump = inputState.GetButtonValue(inputButtons [0]);
if (ColissionState.standing) {
if(canJump){
OnJump();
}
}
}
protected virtual void OnJump(){
var vel = body2d.velocity;
body2d.velocity = new Vector2 (vel.x, jumpSpeed);
}
Thank you!
Answer by Jessespike · Dec 07, 2015 at 10:17 PM
You need a reference of ColissionState.
public ColissionState colState;
void Update() {
if (colState.standing) {
}
}
Check this out: object reference is required to access non-static member - What does this mean?
Your answer
![](https://koobas.hobune.stream/wayback/20220612051709im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object reference not set to an instance of an object 0 Answers
Player passenger moving when being pushed by two platforms 0 Answers
My character won't stop crouching, they dont stop crouchin 2 Answers
Unity 5: 2D Platformer: Trigger/Collisions problem 0 Answers
2D jump problem when hits wall 0 Answers