Hey everyone !
Everytime my player moves I’d like to store some double-float values about where he passed into a list and later assign coins that i pick up to those values (imagine a trail of items behind a snake). Every new move creates 4 points with an X and Y value that need to be stored for later use (hence I need 2 floats per point). I’ve managed to create a 2 dimensional list of floats, but for some reason I get a cast error on the lines where I declare the float[,] firstSpot, float[,] secondSpot, etc, saying I can’t convert a float to an int even tho it seems to me I’ve got floats on both sides of the line.
The second part of the code just enables picked up objects to stick to a point where the snake has passed. I hope this makes sense! Thank you!
EDIT: I initialised my arrays on top:
public List<GameObject> ballsList = new List<GameObject> ();
public List<float[,]> posList = new List<float[,]>();
then later:
public void SnakeBuilder(int dir, float pX, float pY){
if (dir == 0) {
float[,] firstSpot = new float[pX, (pY - .25f)];
float[,] secondSpot = new float[pX, (pY - .50f)];
float[,] thirdSpot = new float[pX, (pY - .75f)];
float[,] fourthSpot = new float[pX, (pY - 1f)];
posList.Insert (0, firstSpot);
posList.Insert (1, secondSpot);
posList.Insert (2, thirdSpot);
posList.Insert (3, fourthSpot);
} else {
float[,] firstSpot = new float[pX - .25f, pY];
float[,] secondSpot = new float[pX - .50f, pY];
float[,] thirdSpot = new float[pX - .75f, pY];
float[,] fourthSpot = new float[pX - 1f, pY];
posList.Insert (0, firstSpot);
posList.Insert (1, secondSpot);
posList.Insert (2, thirdSpot);
posList.Insert (3, fourthSpot);
}
for (int i = 0; i < ballsList.Count; i++) {
ballsList <em>.transform.position = new Vector3 ((float)posList _.GetValue (0), (float)posList *.GetValue (1), 0f);*_</em>
* }*
* }*
[98564-screen-shot-2017-07-27-at-163754.png|98564]