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. Dismiss Notice

Non-invocable member 'Teleport' cannot be used like a method.

Discussion in 'Scripting' started by Corrothon, Feb 28, 2021.

  1. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    It says "
    Non-invocable member 'Teleport' cannot be used like a method." and I don't know how to fix it

    Edit: forgot to tell that a dude in a discord server helped me fix it
     
    Last edited: Feb 28, 2021
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    Is your Teleport a Coroutine? :O

    let us also see the "Teleport" Function
     
  3. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    Here's my whole script for it :))
    (I watched a tutorial and followed his code)

    Code (CSharp):
    1.  public GameObject Portal;
    2.     public GameObject Player;
    3.     // Start is called before the first frame update
    4.     void Start()
    5.     {
    6.      
    7.     }
    8.  
    9.     // Update is called once per frame
    10.     void Update()
    11.     {
    12.      
    13.     }
    14.     public void OnTriggerEnter2D(Collider2D other)
    15.     {
    16.         if(other.gameObject.tag == "Player")
    17.         {
    18.             StartCoroutine (Teleport());
    19.         }
    20.     }
    21.  
    22.         IEnumerator yes()
    23.         {
    24.                 yield return new WaitForSeconds (1);
    25.                 Player.transform.position = new Vector2(Portal.transform.position.x,Portal.transform.position.y);
    26.         }
    27.  
    28. }
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
  5. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    488
    I would suggest going back and looking at that tutorial again, or if this is exactly what they did then maybe go to a different tutorial as what you have provided definitely does not work. You are trying to start a coroutine called
    Teleport
    , but nowhere in your script do you have a coroutine method named
    Teleport
    . Instead you seem to have named your coroutine (IEnumerator)
    yes
    .
    Either change this line:
    Code (csharp):
    1. IEnumerator yes()
    to be:
    Code (csharp):
    1. IEnumerator Teleport()
    Or go back to the tutorial and make sure you have followed exactly what they have done. If you have, and they have made this same mistake then they should be correcting it later in the tutorial - if they don't then you should not continue following the tutorials if this is the quality of stuff they put out.