how to save positions in Vector3 Array und move playerobjekt to the saved position in array's??


im wiriting a Ludo in 3D in C# in Unity 5.
I want to save all the positions on gamefield where the player can move in a vector3 array.
I did it so:

public class gameController : MonoBehaviour {

public List<Vector3> playgroundForRed;

void start () {
List<Vector3> playgroundForRed= new List<Vector3>(); 

// here i want to fill the arrayList with positions of gameobject I made for every position the player shall move (SFeld is the gameObject where the player can move)


Then after the dice roll a 6 the player shall move out of his base to SFeld1 position: i did it like this in update():

GameObject.Find("PlayerR1").transform.position = rotesSpielFeld[0];

But this don’t work. The player doesn’t move.

I realy don’t know what I have to do now…

On the otherside I tried to save every single position direct in Unity like this:



The player jump to the Green Base 69099-movementredplayer1.jpg

(This position isn’t saved in the vector3 array) - there is no position where he moved ^^
But the Player has to go to the first red field on the Playground.

But when I write

GameObject.Find("PlayerR1").transform.position = GameObject.Find("SFeld1").transform.position;

The Player move to the right position, but then I would have a problem on the nice dice roll.
Thats why why I thought to save the positions in the array so i can “just” add the dice number to the next index.

I realy hope someone can help me…

Best Regards!!


so i made it with keyboard input you can edited as you want & the good news is all we need is one short script for all & don’t worry values are different in each object since we assign values in inspector for each object :

int currint;
public List<Vector3> poslist = new List <Vector3>();// make 7 elements in inspector!
public int dice;
void Update(){
    if(my turn){ //assuming you made something to detect turn
        currint = poslist.FindIndex (d=>d == transform.position);
		      dice = Random.Range (1,6);
	          transform.position = poslist[currint + dice];

pay attention :

  1. because arrays & lists start from 0 i made 7 elements & the zero will hold the main position of player so adjust targeted positions from 1 to 6 as desired .
  2. you will face error if transform.position > poslist indexes i mean if you @ poslist[4] & the dice number is 4 player should go to poslist[8] which we don’t have .
  3. so i don’t know what is the limitation of positions & what should happen if player reaches the end .