Here is your code opened in Visual Studio Community 2017 (which is a free tool)
Then I use Edit | Advanced | Format document
You've got a loop with no {}
You forgot to close your update routine. Put a } in.
Here is your fixed code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tilemanager : MonoBehaviour
{
public GameObject[] tilePrefabs;
private Transform playerTransform;
private float spawnZ = 0.0f;
private float tileLegnth = 12.44f;
private int amnTilesOnScreen = 7;
// Start is called before the first frame update
private void Start()
{
playerTransform = GameObject.FindGameObjectsWithTag("Player").transform;
for (int i = 0; i < amnTilesOnScreen; i++)
{
// You forgot these {}
}
}
// Update is called once per frame
private void Update()
{
{
if (playerTransform.position.z > (spawnZ - amnTilesOnScreen * tileLegnth))
{
SpawnTile();
}
}
} // You missed this } here.
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 += tileLegnth;
}
}
thanks for the reply, I'm just getting one error message now, think you could help me with fixing it?
ErrorCS1061 'GameObject[]' does not contain a definition for 'transform' and no accessible extension method 'transform' accepting a first argument of type 'GameObject[]' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\Jimmy\endless runner\Assets\tilemanager.cs 17 Active
Note: Many variables in the GameObject class have been removed. To access, for example GameObject.renderer in csharp use GetComponent<Renderer>() instead.
You'll find this a lot with older tutorials. The method of obtaining components has changed. Use the following instead in your Start function;
4 comments
Here is your code opened in Visual Studio Community 2017 (which is a free tool)
Then I use Edit | Advanced | Format document
You've got a loop with no {}
You forgot to close your update routine. Put a } in.
Here is your fixed code:
thanks for the reply, I'm just getting one error message now, think you could help me with fixing it?
ErrorCS1061 'GameObject[]' does not contain a definition for 'transform' and no accessible extension method 'transform' accepting a first argument of type 'GameObject[]' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\Jimmy\endless runner\Assets\tilemanager.cs 17 Active
From https://docs.unity3d.com/ScriptReference/GameObject.html
You'll find this a lot with older tutorials. The method of obtaining components has changed. Use the following instead in your Start function;