I’ve been working on this game for a few days and I want to be able to make the FPS Controller disable gravity once it exits the planets outer object, this is my current code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class IsOnPlanet : MonoBehaviour {
public GameObject other;
public Rigidbody rb = other.GetComponent<Rigidbody> ();
// Use this for initialization
void Start () {
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.layer == 8)
{
this.rb.useGravity = true;
}
}
}
Here’s the error : Assets/Scripts/IsOnPlanet.cs(9,24): error CS0236: A field initializer cannot reference the nonstatic field, method, or property `IsOnPlanet.other’