platforms spawning towards my player
hello guys firstly i am very sorry if my question is dump. i am newbie. i am creating a 2d game like doodlejump. I spawn platforms randomly but somewhere platforms spawn towards my player. here is a photo: http://imgur.com/a/PLYCn Here is my code:
`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour {
public Transform player; //obj to track is player
float playerHeightY; // height at which camera will adjust to
//defining platform prefabs
public Transform step;
public Transform upDown;
public Transform doubleJump;
public Transform justStep;
private float platformNum; //number of selected platform
private float platformCheck;
private float spawnPlatformsTo;
void Start () {
player = GameObject.FindGameObjectWithTag ("Player").transform;
PlatformSpanner(-2.0f); //seed of randomizing
}
void Update () {
playerHeightY = player.position.y;
if (playerHeightY > platformCheck) {
PlatformManager ();
}
}
void PlatformManager() {
platformCheck = player.position.y + 15;
PlatformSpanner (platformCheck + 15);
}
void PlatformSpanner(float floatValue){
float y = spawnPlatformsTo;
while(y <= floatValue){
float x = Random.Range (-2.35f, 2.35f);
platformNum = Random.Range(0f,.9f); //which one of prefabs
Vector2 posXY = new Vector2(x,y);//position of prefabs
if (platformNum > 0.8) {
Instantiate (upDown, posXY, Quaternion.identity);
}
else if (platformNum > 0.9) {
Instantiate (doubleJump, posXY, Quaternion.identity);
}
else if (platformNum > 0.7) {
//object, position, identitiy
Instantiate (step, posXY, Quaternion.identity);
}
else if (platformNum > 0.5) {
//instantiating prefabs at runtime
Instantiate (justStep, posXY, Quaternion.identity);
}
y += Random.Range (0.5f,1.5f);
}
spawnPlatformsTo = floatValue;
}
}
Comment
Your answer
Follow this Question
Related Questions
Client Spawning Player Objects 0 Answers
Spawning issues 1 Answer
my objects is spawning on the wall 1 Answer
Random spawn script 1 Answer
make enemy fire at randomly times? 0 Answers