Why am I getting this error on my code “A field initializer cannot reference the non-static field, method, or property ‘BeastSheild.parent’”
public GameObject sheild;
public GameObject parent;
public int x = parent.transform.position.x;
public int y = parent.transform.position.y;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
SpawnSheild();
}
}
void SpawnSheild()
{
var spawnedSheild = Instantiate(sheild, new Vector3(x + .5f, y, 0), Quaternion.identity);
spawnedSheild.transform.parent = parent.transform;