i try to do this script but there is an error, how can i fix it?? Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpawnPlatform : MonoBehaviour { public Vector3 SpawnPosition; public float MaxWidth; public float MinWidth; public float MaxLenth; public float MinLenth; public float MoveSpeed; public float ScaleSpeed; private GameObject cube; IEnumerator Start () { yield return StartCoroutine (Spawn ()); } void Start () { cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = SpawnPosition; cube.transform.localScale = RandomLenth(); } void Update() { cube.transform.position += -Vector3.right * Time.deltaTime * MoveSpeed; cube.transform.localScale += new Vector3(Time.deltaTime, Time.deltaTime, Time.deltaTime) * ScaleSpeed; } Vector3 RandomLenth() { return new Vector3(Random.Range(MinLenth, MaxLenth),1,1); } IEnumerator Spawn() { while (true) { yield return new WaitForSeconds (Random.Range (1, 5)); } } }
First of all, you need to use code tags. See this thread: https://forum.unity.com/threads/using-code-tags-properly.143875/ You also need to post the error
You can have only one Start method. The void one. For starters, also post your error message(s) and put the code in code tags here in your forum post.
Start (and some others of Unity's so called "messages") can actually be declared having an IEnumerator as return value. The engine will be aware of it and will start it as a coroutine instead. Anyway it's true, he has to choose the one or the other.
Since this doesn't seem to have any dependencies on other objects, the easiest fix would be to rename the void Start() to Awake(). I'm assuming you're aware the Spawn() function doesn't actually do anything useful, though.