Syntax troubles (GetComponent and changing variables)

Hello. It seems a lot of other people have trouble accessing and changing variables in other scripts/components however I’ve managed to make myself a problem that the other answers I’ve read weren’t about to address.

I have a bool I want to change that lies on a different script. Both the script making the change and the script containing the changing variable lie on the same gameObject.

Can someone point out what I’m doing wrong? I’m working in C#

var go = this.gameObject;
go.GetComponent("PlayerStateSync").moving = false;

That tells me UnityEngine.Component doesn’t contain a definition for the “moving” bool I’m trying to reference.

var go = this.gameObject;
var com = go.GetComponent("PlayerStateSync"); = false:

That tells me UnityEngine.GameObject can’t find a definition for the bool.

Try this instead

var go = this.gameObject;
var com = go.GetComponent<PlayerStateSync>();
com.working = false;

Or if you want to be really fancy

GetComponent<PlayerStateSync>().working = false;

This assumes that PlayerStateSync is a subclass of MonoBehaviour.