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

Question Invoking a method from another script with string as its parameter

Discussion in 'Scripting' started by Akaksona, Dec 18, 2022.

  1. Akaksona

    Akaksona

    Joined:
    Oct 30, 2021
    Posts:
    2
    Hello people, I've run into a small problem I coulnd't find solutions for online. I am trying to invoke a method in another script using its parameter name but the invoking fails.

    script 1 snippet:
    Code (CSharp):
    1.     public void ArtifactTaken(string artifact)
    2.     {
    3.         Invoke(nameof(artifact), 0.1f);
    4.     }
    script 2 snippet:
    Code (CSharp):
    1.     private void OnTriggerEnter2D(Collider2D collision)
    2.     {
    3.  
    4.         if(collision.gameObject.layer == 9)
    5.         {
    6.             playerArtifacts.ArtifactTaken(collision.gameObject.name);
    7.             //win
    8.         }
    9.  
    10.     }
     
  2. Akaksona

    Akaksona

    Joined:
    Oct 30, 2021
    Posts:
    2
    I fixed it, nameof was extra in the first snippet
     
    BenjaminApprill likes this.