So I’m creating an array of Vector2 Objects, to store x values, and then i want to read them out, but unity throws this:
what am i missing?
My code looks something like this
public class Main : MonoBehaviour
{
public Vector2[] data = new Vector2[]
{
new Vector2 (0, 0),
new Vector2 (10, 80),
new Vector2 (20, 110),
new Vector2 (30, 50)
};
private float getvaluey;
public void Update()
{
getvaluey = data.y[2];
}
}
edit:
stored the values to a temp list and now it works, but is this necessary, I mean like having basically 2 arrays, one massive and another list?
I’ve tried the code example you posted with the change that andeeeee wrote and I have no issues.
using UnityEngine;
public class Main : MonoBehaviour
{
public Vector2[] data = new Vector2[]
{
new Vector2 (0, 0),
new Vector2 (10, 80),
new Vector2 (20, 110),
new Vector2 (30, 50)
};
private float getvaluey;
public void Update()
{
getvaluey = data[2].y;
}
private void OnGUI()
{
GUILayout.Label( getvaluey.ToString() );
}
}
The only problem I can think of is that the contents of the data variable has been modified using the inspector. E.g. the array size have been set to something less than 3.
the strangest thing is that indeed at soem point it works, the code itself should be ok, so i’m guessing my Mono has gone nuts somehow… because it provides me only data.y and never data*.y (liek it should be) and some times it works, but mostly it throws me an error.*
hi ravel wud u able to do an arraylist in unity?its like displaying your frends profile pic using plane in unity?sorry didnt know how to use araylist in unity.