Hello, what I want to do is that when the position of the player is equal to the previous position only that in the x I advance 10
This is my script but it doesnt work:
public GameObject[] posibleIslands;
public GameObject IslandPrefab;
public float Range1;
public float Range2;
public float Range3;
public float Range4;
public float Range5;
public float Range6;
private float valueX;
private float valueY;
private float valueZ;
public Vector3 myPosition;
public Vector3 myOldPosition;
public Vector3 pos;
void Update ()
{
pos = new Vector3(valueX, valueY, valueZ);
valueX = Random.Range (Range1, Range2);
valueY = Random.Range (Range3, Range4);
valueZ = Random.Range (Range5, Range6);
myPosition = transform.position;
if (myPosition == myOldPosition + new Vector3(10, 0, 0) || myPosition == myOldPosition - new Vector3(10, 0, 0) || myPosition == myOldPosition + new Vector3(0, 0, 10) || myPosition == myOldPosition - new Vector3(0, 0, 10))
{
for (int i = 0; i < Random.Range (1, 5); i++)
{
GenerateIsland ();
i = 0;
}
myOldPosition = myPosition;
}
}
public void GenerateIsland()
{
int posibleIslandsInt = Random.Range (0, posibleIslands.Length);
if (posibleIslandsInt == 0)
{
IslandPrefab = posibleIslands [0];
}
if (posibleIslandsInt == 1)
{
IslandPrefab = posibleIslands [1];
}
if (posibleIslandsInt == 2)
{
IslandPrefab = posibleIslands [2];
}
Instantiate(IslandPrefab, pos, Quaternion.identity);
}