hello everyone
i have written a scene where platform spawned randomly until they reach
the max platforms i wanted
my problem is that i want to spawn a game object at the last platform
to be the finish point
how can i do that?
i’ve tried spaw script but the spawning isn’t doing well it’s always spawn at the first platform
my code is a little variation of the basic platform 2d game in the tutorials here
just for fun my end object is called stan
using UnityEngine;
using System.Collections;
public class spawnstan : MonoBehaviour {
public Transform stanpos;
public GameObject stan;
// Use this for initialization
void Start () {
if (spawnst==spawnstmax)
{
Instantiate(stan, stanpos.position, Quaternion.identity);
spawnst = 0;
}
}
// Update is called once per frame
void Update()
{
}
}
this is the spawnplatform code
using UnityEngine;
using System.Collections;
public class spawnmaneger : MonoBehaviour
{
public int maxPlatforms = 5;
public GameObject Platform;
public float horizontalMax = 6.5f;
public float horizontalMin = 14f;
public float verticalMin = -6f;
public float verticalMax = 6f;
private Vector2 origin;
// Use this for initialization
void Start () {
origin = transform.position;
spawn();
}
void spawn()
{
for (int i = 0; i < maxPlatforms; i++)
{
Vector2 randpos = origin + new Vector2(Random.Range(horizontalMin,horizontalMax),Random.Range(verticalMin,verticalMax));
Instantiate(Platform, randpos, Quaternion.identity);
origin = randpos;
if (i == maxPlatforms-1)
{
spawnstan.spawnst ++;
spawnstan.spawnstmax = maxPlatforms-1;
spawnstan.vector = origin;
}
}
}
}