Hi guys!
I am trying to make an multiplayer Endless Runner game, like Temple Run
What i m trying to do is to make a script that spawning platform whenever the player is beginning to reach the end of the platform.Script is based on finding the position of the ONE gameobject tagged “player” and tell when platforms can spawn
The problem is i have a script for that, but because are MORE than 1 gameobject named “player” in a multiplayer, the script is useless
I tried many “beginners ideas” to make the script do his purpose, but no one worked
Can someone help me out with a code or editing the existing one?
i will gave you the original code for reference.
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PlatformSpawn : NetworkBehaviour
{
public GameObject[] tilePrefabs;
private Transform playerTransform;
private float spawnZ = 0.0f;
private float tileLength = 12.0f;
private int amnTilesOnScreen = 7;
void Start ()
{
playerTransform = GameObject.FindGameObjectWithTag ("Player").transform;
for(int i=0; i<amnTilesOnScreen; i++)
{
SpawnTile();
}
}
void Update ()
{
if(!isLocalPlayer)
{
if(playerTransform.position.z>(spawnZ -amnTilesOnScreen*tileLength))
SpawnTile();
}
}
private void SpawnTile(int prefabIndex = -1)
{
GameObject go;
go = Instantiate (tilePrefabs [0]) as GameObject;
go.transform.SetParent (transform);
go.transform .position = Vector3.forward * spawnZ ;
spawnZ+= tileLength;
}
}
`