- Home /
Working script runtime
Hello, I have working script, which generate obstacles. In game, I wanted to do few levels of difficulty. For example: 1 level = 5 the easiest obstacles. 2 level = 5 next harder obstacles etc. But that obstacles are all generated at start of the game. How to do that the eg. second script (with obstacles from 2 level) will run from a specific position player? I just do not want to 5 levels is generated at the start of the application, but formed gradually along with the position of the player.
Here's code of generator obstacles:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Platforms : MonoBehaviour {
public List <Obstacles> obs = new List<Obstacles>();
public Vector3 StartPos = Vector3.zero;
private Vector3 nextPos;
void Start ()
{
LoadObstacles();
}
void LoadObstacles()
{
nextPos = Vector3.zero;
foreach (Obstacles o in obs)
{
for(int x = 0; x < 40; x++) // or how many you want to be instantiated
{
nextPos.y = StartPos.y + Random.Range(o.Positions.min.y, o.Positions.max.y);
int randIndex = Random.Range(0, obs.Count);
Instantiate(obs[randIndex].Prefab, StartPos + nextPos, Quaternion.identity);
nextPos.x += Random.Range(o.Positions.min.x, o.Positions.max.x);
}
}
}
}
[System.Serializable]
public class Obstacles
{
public Transform Prefab;
public pos Positions;
}
[System.Serializable]
public class pos
{
public Vector2 max;
public Vector2 min;
}
Regarding player, I'm using scripts "Sample Assets" from Unity Asset Store.
I don't understand what you're asking? do you want the game to get harder? ie. the first 5 obstacles are easy and then the next 5 are harder and so on? or do you want them so select the difficult beforehand and then based on that, create harder obstacles?