Variable out of context... newbie...

Hi guys,

Just starting out with Unity coding. Can someone point out my error please? I want to pass in 2 integers, to retrieve the vector3 co-ordinates.

I thought declaring the fieldPos at the start would make it global to the class?

    Vector3[,] fieldPos = new Vector3 [21, 42];

    void Start () {
        InitialiseField();
    }

    private void InitialiseField () {
    int x, z;
       blah...
    }

    public Vector3 GetCoOrdinates(int x, int z) {
        Vector3 coOrdinates = new Vector3();
        coOrdinates = fieldPos(x,z);
        return coOrdinates;
    }

The error is on line 15, variable out of context.

It is preferable if you post your code within code tags. For example:

int i = 0;

Makes it easier to read.
Also, which line is the error on?

Ooops, I had parenthesis instead of square brackets around the fieldPos :sweat_smile:

1 Like