- Home /
Question by
$$anonymous$$ · Aug 23, 2017 at 06:30 PM ·
scripting probleminstantiate
I'm randomly instantiating my map but my map either gets to far ahead or gets behind and my player starts falling off
I'm randomly instantiating my map but my map either gets to far ahead or gets behind and my player starts falling off, how can I make my map instantiate at the same pace as my character is going but also gets destroyed when the map gets behind my character, because this game is going to be for android and my phone starts lagging after a while of running the game. here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
public class Map : MonoBehaviour
{
public Transform normalMap;
public Transform holeinMid;
public Transform holeLeft;
public Transform holeRight;
public string mapLock = "n";
public float mapNum;
public float mapPoNum = 25;
public float mapGenSpeed = 1.15f;
public float mapGenSpeedAcc = 0.000005f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update() {
if (mapPoNum < 100000000000)
{
mapNum = Random.Range(0, 100);
}
if ((mapNum < 30) && (mapLock == "n"))
{
Instantiate(normalMap, new Vector3(0, 0, mapPoNum), normalMap.rotation);
mapPoNum += 6;
mapLock = "y";
StartCoroutine(stopMap());
}
if ((mapNum > 30) && (mapNum < 54) && (mapLock == "n"))
{
Instantiate(holeLeft, new Vector3(0, 0, mapPoNum), holeRight.rotation);
mapPoNum += 6;
mapLock = "y";
StartCoroutine(stopMap());
}
if ((mapNum > 54) && (mapNum < 78) && (mapLock == "n"))
{
Instantiate(holeinMid, new Vector3(0, 0, mapPoNum), holeinMid.rotation);
mapPoNum += 6;
mapLock = "y";
StartCoroutine(stopMap());
}
if ((mapNum > 78) && (mapNum < 101) && (mapLock == "n"))
{
Instantiate(holeRight, new Vector3(0, 0, mapPoNum), holeRight.rotation);
mapPoNum += 6;
mapLock = "y";
StartCoroutine(stopMap());
}
if (Player.moveSpeed < Player.maxiumSpeed)
{
mapGenSpeed = mapGenSpeed - (mapGenSpeed / 10000000000);
}
}
IEnumerator stopMap()
{
yield return new WaitForSeconds(mapGenSpeed);
mapLock = "n";
}
}
Comment