Hello,
I’m trying to get a function in my CharacterController script to reference a coroutine from another script.
Basically the flow is
on left mouse click → check the selected skill → begin casting skill via coroutine → shoot the skill
Here is some sample code: I’m running into a myriad of issues:
SCRIPT 1;
using UnityEngine;
using System.Collections;
public class CharControllerScript : MonoBehaviour {
void Update () {
if (Input.GetKeyDown (KeyCode.Mouse0)) {
shoot ();
}
}
public void shoot(){
StartCoroutine (ClassSpecificSkills.shoot_FrostBolt);
}
}
SCRIPT 2:
using UnityEngine;
using System.Collections;
public class ClassSpecificSkills : MonoBehaviour {
public static IEnumerator shoot_FrostBolt(){
for (float f = 10f; f > 0; f -= 0.1f) {
Debug.Log ("Coroutine running 10 times");
}
yield return null;
}
}
As you can see, my first script (CharController) tries to start a coroutine which is written in a second script (classSpecificSkills). The error I’m getting is the following:
-
Assets/CharControllerScript.cs(22,17): error CS1502: The best overloaded method match for `UnityEngine.MonoBehaviour.StartCoroutine(System.Collections.IEnumerator)’ has some invalid arguments
-
Assets/CharControllerScript.cs(22,17): error CS1503: Argument
#1' cannot convert
method group’ expression to type `System.Collections.IEnumerator’ -
Assets/CharControllerScript.cs(24,17): error CS0127: `CharControllerScript.shoot()': A return keyword must not be followed by any expression when method returns void
-
Assets/CharControllerScript.cs(24,24): error CS0119: Expression denotes a
type', where a
variable’,value' or
method group’ was expected
I’ve been struggling with this for a few days, trying to get the syntax correct for coroutines but keep going in circles.
Any help is appreciated.
Thanks!