Type 'Object' does not support slicing - Vector2

Hi All

I am getting the above error, but have been unable to find a workable solution. Code only forms error on pragma strict. I understand that aPos.y and aPos.x have invalid values… but could someone help explain how to fix?

Many thanks!

function GetTile(aPos : Vector2){
	return levelArray[aPos.y][aPos.x];
}

Array indexing requires an integer paramater- think of it like this:

Imagine you have a list of items, from 0 to 9. If you want to get item 4, you look at

list[4]

However, you can’t look at item 3.6, or item 7.2- how do you index a non-exact number?

The problem you are having is that the ‘x’ and ‘y’ values in a Vector2 are not limited to integers. They are both floating-point numbers, and so cannot be used to index an array.

So, just convert them first.

levelArray[Mathf.RoundToInt(aPos.y)][Mathf.RoundToInt(aPos.x)];

should give you what you want (assuming that ‘levelArray’ has been declared properly, which I’m not convinced is the case- the ‘object does not support slicing’ error sounds like you’re trying to index an object that isn’t any kind of list or array, but it could be a symptom of the above problem).