Hello! I'm trying to put the position of each Transform into an array, but it won't let me(says some cross between Transforms and Vector3). Do anyone know a way around this? js. Code (csharp): var savePosition : boolean; var positions : Transform[]; public function Save(){ if(savePosition){ for(var i = 0; i < positions.Length; i++){ data.positions[i] = positions[i].transform; } } } public function Load(){ if(savePosition){ for(var i = 0; i < positions.Length; i++){ for(var p : Transform in positions) p.position = data.positions[i]; } } }
I am guessing that you are trying to assign your transform to a position ( Vector3) on Line 8. Try using Code (CSharp): data.positions[i] = positions[i].transform.position;
I changed line 17 to this: Code (csharp): p.transform.position = data.positions[i].transform.position; But I still have the error in line 8.
I'm not good at Unity/JavaScript, but in c# i have to define a size for an array before using it. The way you are using the array looks as example 2 http://docs.unity3d.com/ScriptReference/Array.html
What Type is data.positions? Because if data.positions isn't ALSO an array of Transforms, this isn't going to work.
This is data: Code (csharp): var data : GameData = new GameData(); This is used from the persistent data code but in JavaScript. Could I turn this into an array?
suggest u change Transform to GameObject Code (CSharp): data.positions[i] = positions[i].transform; positions are Transform Type it maybe work this way Code (CSharp): data.positions[i].gameobject = positions[i].gameobject;
What is game data? Paste the class. You're trying to cast a Vector3 to a Transform, so that's the problem.
This is my class as well, it's also a Transform. Code (csharp): class GameData(){ var positions : Transform[]; }
where do you set the size of your array ? Also changing the number of transform you want to store, you have to rebuild the array because arrays are not resizeable.