Coroutine cannot be started error!!!

Hi, First of all, i’m sorry, i have almost no prior coding experience so excuse me if this question is dumb, I’m trying to start a coroutine event, this event increases the speed for my game object by 5 each 7.5 seconds, however, i keep getting Coroutine cannot be started error in Unity’s console, script and image of error is below:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mover : MonoBehaviour
{
    public float speed;

    void Start ()
    {
        StartCoroutine ("MyEvent");
        GetComponent<Rigidbody>().velocity = transform.forward * speed;
    }
    private IEnumerator MyEvent2()
    {
        while (true) {
            yield return new WaitForSeconds (7.5f);
            speed = speed + 5;
        }
    }
}

Error:

The names don’t match. You’re calling “MyEvent” and the name is “MyEvent2”

yea sorry when i was playing with the script i added event 2, but even if names match, the coroutine would not add 5 speed every 7.5 second, i have this script attached to a Prefab enemies that spawn, maybe that’s the problem?

You’re adding to speed just fine. “void Start ()” is only called once during a gameobject’s life, and this happens to be the only time you tell the rigidbody what its velocity should be.

You can change your speed variable all you want, it won’t do anything to your rigidbody unless you tell it to.

You should take the line where you define your rigid body’s velocity in your start method and copy it below the line where you increase the speed, in your coroutine.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour
{
    public float speed;
    void Start ()
    {
        StartCoroutine ("MyEvent");
    }
    private IEnumerator MyEvent()
    {
        GetComponent<Rigidbody>().velocity = transform.forward * speed; //does this once
        while (true) {
            yield return new WaitForSeconds (7.5f);
            speed = speed + 5;
            GetComponent<Rigidbody>().velocity = transform.forward * speed; // does this every 7.5 sec
        }
    }
}

Don’t use the string method to start a coroutine. It’s a bad idea.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour
{
    public float speed;
   RigidBody rb;
    void Start ()
    {
        rb = GetComponent<RigidBody>(); // cached.
        StartCoroutine (MyEvent());
    }
    private IEnumerator MyEvent()
    {
        rb.velocity = transform.forward * speed; //does this once
        WaitForSeconds wfs = new WaitForSeconds(7.5f); // cached
        while (true) {
            yield return wfs;
            speed = speed + 5;
            rb.velocity = transform.forward * speed; // does this every 7.5 sec
        }
    }
}