Hello,
i’m trying to access vector 3 list from another scene and assign it’s values to multiple game objects positions.
the code is working well, but it gives me this error:
NullReferenceException: Object reference not set to an instance of an object
test1.Update () (at Assets/Script/Scene choos pieces/test1.cs:10)
the code:
1- code which set the values in the first scene:
public class SGPositions : MonoBehaviour {
public GameObject[] pieces;
public List<Vector3> piecesPos;
void Update () {
piecesPos = new List<Vector3>();
foreach (GameObject go in pieces) {
piecesPos.Add (go.transform.position);
}
}
}
2- code attached to a game object in the two scenes:
public class test1 : MonoBehaviour {
public List<Vector3> piecesPosTest1;
void Awake() {
DontDestroyOnLoad(transform.gameObject);
}
void Update () {
piecesPosTest1 = GameObject.Find ("scene1 GmObj").GetComponent<SGPositions>().piecesPos;
}
}
3- code which get the values from the first scene and assign them to game objects positions:
public class SetPieces : MonoBehaviour {
public GameObject[] playerShips;
public List<Vector3> piecesPosSetPieces;
void Start(){
piecesPosSetPieces = GameObject.Find ("scene1,2 GmObj").GetComponent<test1>().piecesPosTest1;
setallpieces ();
}
void setallpieces() {
for(int i = 0; i < 2; i++) {
playerShips [i].transform.position = piecesPosSetPieces [i];
}
}
}
sorry for my bad english, please HELP.