Pretty new at this, so apologies if I’m missing an easy bit of logic. Basically, I have a Crossy Roads style LevelGenerator that is called by the Manager at Start() and to build 30 tiles, then the LevelGenerator creates a tile everytime the player jumps forward. I have two different scales of tiles; some tiles are 2 units on the z, some are one unit.
Works great until you respawn at a Checkpoint. When you respawn, I reset the levelgenerator’s Vector3 to match the player, then recently the nearest fix I have done is pass in this line:
levelGenerator.lastPos = Checkpoint.reachedPoint.z + 46.5f;
The 46.5 offset seems to work sometimes and sometimes not. I believe it is because, as I mentioned, some tiles are scaled 2 z, so randomly 30 levels could be at most 60 tiles and at least 30 tiles. Here’s my code for the LevelGenerator:
public class LevelGenerator : MonoBehaviour
{
public List<GameObject> platform = new List<GameObject> ();
public List<float> height = new List<float> ();
private int rndRange = 0;
public float lastPos = 0;
private float lastScale = 0;
public bool isVisible = false;
public void RandomGenerator ()
{
rndRange = Random.Range ( 0, platform.Count );
for ( int i = 0; i < platform.Count; i++ )
{
CreateLevelObject ( platform _, height *, i );*_
* }*
* }*
* public void CreateLevelObject ( GameObject obj, float height, int value )*
* {*
* //how we set the pieces in.*
* if ( rndRange == value )*
* {*
* GameObject go = Instantiate ( obj ) as GameObject;*
_ float offset = lastPos + ( lastScale * 0.5f );
offset += (go.transform.localScale.z ) * 0.5f;_
* Vector3 pos = new Vector3 ( 0, height, offset );*
* go.transform.position = pos;*
* lastPos = go.transform.position.z;*
* lastScale = go.transform.localScale.z;*
* go.transform.parent = this.transform;*
* }*
* }*
}
Basically, I think the difference of the 1 and 2 on the lastScale is causing the issue. Is there any simple way that I could have the manager check for the number of tiles the LevelGenerator is returning on Start() or perhaps force it?