Program Return Type

Hi
I’m trying to create a program that will let me make the ground scroll for a while (c#) but my program movement doesn’t have a return type and im not sure what to use.
I’ve done this so far…

using UnityEngine;
using System.Collections;

public class GroundMovement : MonoBehaviour {

public bool characterSelected;
private int groundCountdown;
public bool groundOneFinnished;

// Use this for initialization
void Start () {
    characterSelected = false;
    groundCountdown = 60;
    groundOneFinnished = false;
    if (characterSelected == true) {
        Movement();
    }
}

public Movement ()
{
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    transform.position = new Vector3(-1.385, 0.0f, 0.0f);
    yield return new WaitForSeconds(0.1);
    groundCountdown = groundCountdown - 1;
    if (groundCountdown == 0) {
        groundOneFinnished = true;
    }
    else
    {
        Movement();
    }
}

}

What should i put as the return type for Movement?
Thanks

You’re using yield statements, so you’ll need to use an IEnumerator as your return type.

Well since you’re using a Coroutine you need, as Eno Khaon said, use IEnumerator as return type it won’t work at all.

The “40” errors are most likely related to the fact that you pass a double value 0.1 to WaitForSeconds instead of a float value 0.1f. Same for the “x” parameter of all your Vector3 constructors. This should fix most errors:

transform.position = new Vector3(-1.385f, 0.0f, 0.0f);
yield return new WaitForSeconds(0.1f);

Next thing is to start a coroutine you need to use StartCoroutine. You can’t call a coroutine like a normal method.

Finally restarting the coroutine is a bad pattern. If you want the code to repeat, use loops. At the moment you set the position every 0.1 seconds to the same position. Do you plan to use different positions in the future? If not you could use another loop:

void Start ()
{
    // [...]
        StartCoroutine(Movement());
    // [...]
}

public IEnumerator Movement ()
{
    while (groundCountdown > 0)
    {
        for(int i = 0; i < 10; i++)
        {
            transform.position = new Vector3(-1.385f, 0.0f, 0.0f);
            yield return new WaitForSeconds(0.1f);
        }
        groundCountdown = groundCountdown - 1;
    }
    groundOneFinnished = true;
}