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

Trying to Invoke method: EndGame.gm.End couldn't be called.

Discussion in 'Scripting' started by thefrogeitan, Feb 23, 2020.

  1. thefrogeitan

    thefrogeitan

    Joined:
    Oct 20, 2019
    Posts:
    7
    i trying to reastart my game after 2 sec but it give me the erorr that in the title
    here my code


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EndGame : MonoBehaviour
    6. {
    7.     public GameMengement gm;
    8.     public GameObject blood;
    9.    
    10.  
    11.  
    12.     private void OnTriggerEnter2D(Collider2D col)
    13.     {
    14.         if(col.tag == "Obstcle")
    15.         {
    16.             Instantiate(blood, transform.position, Quaternion.identity);
    17.             Invoke("gm.End", 2f);
    18.         }  
    19.     }
    20.  
    21.  
    22. }
    23.  
     
  2. Technokid2000

    Technokid2000

    Joined:
    Dec 18, 2016
    Posts:
    36
    Looks like the code cannot invoke "gm.End". Make sure that gm is infact defined in the inpector, and make sure that "End" is a function found in gm
     
  3. Technokid2000

    Technokid2000

    Joined:
    Dec 18, 2016
    Posts:
    36
    Upon looking at it further, I realise the problem. You are trying to call EndGame.gm.End, which doesn't exist. What you want in line 17 is "gm.Invoke("End", 2f);". That's your solution! Hope that's what you were after!
     
    orionsyndrome likes this.
  4. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    I like GameMengement, sounds like a respectable game dev business that releases on Steam.. daily.

    Seriously, why Invoke anything, unless it's an event or you're knee deep into reflection? Where do you people learn to code in C#? I want some of that.