I’m relatively new to Unity. I wanted to program a simple gravity script, had a few errors, fixed them, then this error popped up.
A field initializer cannot reference the non-static field, method, or property ‘Component.transform’
How do I fix it?
The code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gravity : MonoBehaviour
{
bool isGreater = transform.position.y.isGreater(0);
void Update()
{
if (isGreater == true)
{
transform.Translate(new Vector3 (0, -1, 0));
}
}