Question by
KraykonDev · Feb 05, 2016 at 04:22 PM ·
spawnobstaclerandomly
Spawn different obstacles
Hello, i got this script that is spawning obstacles but is just spawning the same prefab every time and i want to randomly spawn other obstacles to! here is the script i am using:
public GameObject barGroup; //bargroup,contains 3 bars left and right
public float distanceBetweenBarGroups;
Transform playerTransform;
void Start()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
OnGameStart();
}
float lastPlayerPosition;
void Update()
{
//if player player somes 6 units distance from its last distance ,then we will create new bar group
if (playerTransform != null && playerTransform.position.y - lastPlayerPosition > 6)
{
createNewGroup();
lastPlayerPosition = playerTransform.position.y; // to store the present ball position y .
}
}
int groupIndex = 1;
void createNewGroup()
{
GameObject barGroupNewInstance = GameObject.Instantiate(barGroup) as GameObject;
barGroupNewInstance.transform.position = new Vector3(-5.21f, distanceBetweenBarGroups * groupIndex, 0); //this will create new bars group
groupIndex++;
}
void OnGameStart()
{
}
you are a boll that if you tap the screen it will flap and its gonna continue like that and obstacles will spawn up.
please help me! :)
Comment
and btw i am using those:
using UnityEngine; using System.Collections; using System;
Your answer
Follow this Question
Related Questions
Spawning random objects not working 2 Answers
Spawn script !! Y axis not working 0 Answers
Instantiate not spawning anything 1 Answer
How to do a Spawn Animation 1 Answer