Y
Y
yungprogrammerlowskill2021-12-31 08:31:30
Unity
yungprogrammerlowskill, 2021-12-31 08:31:30

Error: Does the non-static field, method, or property 'GameObject.transform' require an object reference?

How to solve this problem?

the code:

void FixedUpdate()
    {
        if (UnityEngine.Input.GetKey(KeyCode.W))
        {
            GameObject.transform.position = new Vector2(GameObject.transform.position.x,
                y: GameObject.transform.position.y + 1.79f);
        }
        if (UnityEngine.Input.GetKey(KeyCode.S))
        {
            GameObject.transform.position = new Vector2(GameObject.transform.position.x,
                y:GameObject.transform.position.y - 1.79f);
        }
        if (UnityEngine.Input.GetKey(KeyCode.A))
        {
            GameObject.transform.position = new Vector2(x:GameObject.transform.position.x + 1.79f,
                 GameObject.transform.position.y);
        }
        if (UnityEngine.Input.GetKey(KeyCode.D))
        {
            GameObject.transform.position = new Vector2(x:GameObject.transform.position.x - 1.79f,
                 GameObject.transform.position.y + 1.79f);
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-12-31
@yungprogrammerlowskill

Replace GameObject with gameObject,
And start by looking at SeaSharp to see what went wrong.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question