So i decided to rebuild a project that i worked on due to big problem which couldent find how to fix , i have the same scripts which was the hardest thing for me , and im allmost going to the same point but I have this 1 problem that stops me from going forward.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class EndlessPaths : MonoBehaviour {
public GameObject[] Paths;
private Transform PlayerTransform;
private float SpawnZ = -20.0f;//the first tile
private float PathZ = 60.0f;//space between tiles
private int MaximumPath = 2;//max paths loaded at a time
private List<GameObject> OpenedPaths;//list of paths that are loaded , deleting the not seen one(olders);
private float SafeZone=8.0f;
private int lastPrefabIndex = 0;
private void Start () {
OpenedPaths = new List<GameObject> ();
PlayerTransform = GameObject.FindGameObjectWithTag ("Player").transform;
for (int i = 0; i <= MaximumPath; i++)
{
if (i < 1)
SpawnPaths (0);//first 1 paths are free from dying
else
SpawnPaths ();//normal paths
}
}
// Update is called once per frame
private void Update () {
if (PlayerTransform.position.z- SafeZone> (SpawnZ - MaximumPath * PathZ))
{
SpawnPaths ();
DeletePath ();
}
}
private void SpawnPaths(int prefabindex = -1)
{
GameObject go;
if (prefabindex == -1)
go = Instantiate (Paths [RandomPrefabIndex ()]) as GameObject;//cloning
else
go = Instantiate (Paths [prefabindex])as GameObject;
go.transform.SetParent (transform);
go.transform.position = Vector3.forward * SpawnZ;
SpawnZ += PathZ;//spawn tile above then here it add the space between tiles and remaking the gameobject Z spawn .
OpenedPaths.Add (go);
}
private void DeletePath()
{
Destroy (OpenedPaths [0]);//delete the clone gameobject of the prefab
OpenedPaths.RemoveAt(0);//revoming it from the list
}
private int RandomPrefabIndex()//randomize the paths
{
if (Paths.Length <= 1)
return 0;
int randomIndex = lastPrefabIndex;
while (randomIndex == lastPrefabIndex)
{
randomIndex = Random.Range(0,Paths.Length);
}
lastPrefabIndex = randomIndex;
return randomIndex;
}
}
MPORTENT TO MENTION : im 99% sure its not the scripts , just made it here cause i know some people will think its because of it so i put here to let them see.
This is the script that attached to an EmptyGame object which called PathManager and his job is to spawn tile endlessly ( like tample run ) and delete those behind , simple , worked perfectly on my last project but here for some reason its screwing with the tile transform.Y , Screenshot by Lightshot ass seen in this picture , the tile i have is on -10.8 on Y and X is 0 and Z is -20 (0,-10.8f,-20) transform , the Y is not 0 because the bridge from the assest I downloaded from the store is build that way cause the transfrom cube itself is not on the bridge ground so 0 is actully higher and i want the bridge to be on the ground , so my player can walk on 0 ( make it more comfrobale for me ) , When im buidling the bridge , putting it on those points and putting it in the prefab folder , then putting it in the List on the path manager script it spawn it on (0,0,-20) Which put it higher Screenshot by Lightshot for no reason at all , the same script worked perfectly on my last project and its also working here good expect the Y probelem ( going endleslly and all the other transfro points (x and z) are well placed ) and this is driving me crazy cause there absulutly nothing that should make that go this.
i allredy posted this probebly befor and got no replies nor people watching this , i truly hope someone can help me cause im newbe , also sorry for my bad english , english isnt my mother tangue ![]()
.