Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Getting errors with cooling weapons+Coroutine sayin strange things and getting errors when I call it

Discussion in 'Scripting' started by harrypotterindy, Jan 10, 2016.

  1. harrypotterindy

    harrypotterindy

    Joined:
    Dec 27, 2014
    Posts:
    15
    :mad::confused::(:oops::(:mad: are my emotions right now. I have no idea how to fix this and when I open up the error method page it says there is no error like this on the website. So I am confused and unsure how to fix this. Please if you think you know how to fix it, tell me. I am not the best at programming, and I've only been making games for 3-4 years. Here is my script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BaseBlaster : MonoBehaviour {
    5.  
    6.     private float blasterHeat;
    7.     private float maxBlasterHeat = 4f;
    8.  
    9.     private bool canShoot = true;
    10.  
    11.     public float blasterFireSpeed;
    12.     public float blasterDamage;
    13.  
    14.     public virtual void Shoot ()
    15.     {
    16.  
    17.     }
    18.  
    19.     public void CoolCheck()
    20.     {
    21.         if (blasterHeat >= maxBlasterHeat)
    22.         {
    23.             canShoot = false;
    24.             //Error below
    25.             StartCoroutine(Cool);
    26.             //Error above
    27.             canShoot = true;
    28.         }
    29.     }
    30.  
    31.     public IEnumerator Cool
    32.     {
    33.      //Error below
    34.         WaitForSeconds(4);
    35.     }
    36.  
    37.     public void Update ()
    38.     {
    39.  
    40.     }
    41. }
    42.  
    Remember, if you think you can fix it, then please by all means go ahead and tell me. BTW I am only 11 yrs old.:D
     
  2. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there!!

    It seems your Cool method isn't returning anything. It's signature indicates it should return an IEnumerator Object. Since it's a coroutine it must yield its return object so try this instead:

    Code (CSharp):
    1. public IEnumerator Cool
    2. {
    3.     yield return new WaitForSeconds(4f);
    4. }
     
  3. OldUnityFool

    OldUnityFool

    Joined:
    Feb 27, 2015
    Posts:
    25
    I think you should use: ()
    public IEnumerator Cool()
     
  4. harrypotterindy

    harrypotterindy

    Joined:
    Dec 27, 2014
    Posts:
    15
    Still, I have errors.
    Argument 1: cannot convert from 'method group' to 'string'
    24 28

    The best overloaded method match for 'UnityEngine.MonoBehaviour.StartCoroutine(string)' has some invalid arguments 24 13

    Here is my script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BaseBlaster : MonoBehaviour {
    5.  
    6.     private float blasterHeat;
    7.     private float maxBlasterHeat = 4f;
    8.  
    9.     private bool canShoot = true;
    10.    
    11.     public float blasterFireSpeed;
    12.     public float blasterDamage;
    13.  
    14.     public virtual void Shoot ()
    15.     {
    16.  
    17.     }
    18.  
    19.     public void CoolCheck()
    20.     {
    21.         if (blasterHeat >= maxBlasterHeat)
    22.         {
    23.             canShoot = false;
    24.             StartCoroutine(Cool);
    25.             canShoot = true;
    26.         }
    27.     }
    28.  
    29.     public IEnumerator Cool()
    30.     {
    31.         yield return new WaitForSeconds(4f);
    32.     }
    33.  
    34.     public void Update ()
    35.     {
    36.  
    37.     }
    38. }
    39.  
     
  5. harrypotterindy

    harrypotterindy

    Joined:
    Dec 27, 2014
    Posts:
    15
    Thank you for your help! I have fixed the problem by adding "()" in front of the word Cool in the StartCoroutine. Thank you everybody!