- Home /
Question by
tuta100 · Aug 24, 2015 at 02:05 PM ·
platformerspawningoffsetendless runnerdifferent objects
Hey how can I spawn a platform after the previous one.
Hey, I want to spawn a random platform every time, but attach to the previous platform, Could some please look at the my code and help me, The platform prefabs are all different sizes. The spawning part is working but I am having trouble attaching one platform to the other perfectly. I have attached this code to the starting platform. Any help would be great. Thanks.
using UnityEngine; using System.Collections;
public class Spawn : MonoBehaviour {
public float spawnSpeed;
public GameObject[] platformPrefabArray;
private GameObject lastCreatedPlatform;
private Vector3 lastPlatformPosition;
public Vector3 offset;
void Awake()
{
spawnSpeed = 1f;
lastPlatformPosition = new Vector3 (0, 0, 1);
offset = new Vector3 (0, 0, 25);
}
void Start()
{
CreatePlatform()
}
void CreatePlatform()
{
lastCreatedPlatform = (GameObject)Instantiate(platformPrefabArray [Random.Range (0, platformPrefabArray.GetLength (0))], lastPlatformPosition + offset, Quaternion.identity);
lastPlatformPosition = lastCreatedPlatform.transform.position;
}
}
Comment
Your answer
Follow this Question
Related Questions
Define position as lower left corner? 0 Answers
2D 360 degress platformer example needed 0 Answers
Platform generation using object pooling 0 Answers
Spawn endless platforms help 0 Answers