I’m trying to limit jumping in this script to only jumping from objects with the “ground” tag but unity comes up with this error.
Assets/PlayeController.cs(19,39): error CS0120: An object reference is required to access non-static member `UnityEngine.Collision.collider'
here is my script
using UnityEngine;
using System.Collections;
public class PlayeController : MonoBehaviour {
public float speed;
public float jumpHeight;
private Rigidbody rb;
private bool isGrounded;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void OnCollisionStay (Collision collisionInfo)
{
if (Collision.other.CompareTag("ground"))
{
isGrounded = true;
}
}
void OnCollisionExit (Collision collisionInfo)
{
isGrounded = false;
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
rb.AddForce (movement * speed);
bool jumpy = Input.GetKeyDown ("up");
if (jumpy && isGrounded)
{
Vector3 jumping = new Vector3 (0.0f, jumpHeight, 0.0f);
rb.AddForce (jumping * speed);
}
}
}
the problem is with the if(collision.other.compareTag(“ground”)) line but I’m not sure what unity wants me to do here.