I am making a simple game in Unity2D and even after numerous tries, CS0120 error still occurs.
I have been already looking thru some tutorials/help but none of them really helped me and I dont wanna mess up my code even more.
//This is the one which I want to call the var from
public class Terraform : MonoBehaviour
{
public int TerraformClick;
void Start()
{
}
void Update()
{
if(Input.GetMouseButtonDown(1))
{
TerraformClick = 1;
}
}
}
//And this is the main script
public class Grass_Follow : MonoBehaviour
{
void Awake()
{
GameObject TerraformButt = GameObject.Find("Terraform");
Terraform terraformScript = TerraformButt.GetComponent<Terraform>(); //finding the object
}
void Update()
{
//probably some mistake in calling the variable
if (Terraform.TerraformClick == 1)
{
Vector3 pz =
Camera.main.ScreenToWorldPoint(Input.mousePosition);
pz.z = 0;
transform.position = pz;
}
else
{
}
}
}
I expect just some small mistake with the variable placement/calling