A
A
Alexander2021-04-29 12:44:01
C++ / C#
Alexander, 2021-04-29 12:44:01

How to call a method from one C# script in another script in Unity?

Unity
has a crypt with a method: public void ShowInterstitial()
I need to call it in another script, in the Die() method,

did I do it right

public GameObject ssilkaNaFirstScript;

 private void Die()
    {

        ssilkaNaFirstScript.GetComponent<FirstScript>().ShowInterstitial();

    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-04-29
@GreenProg

Then right away

[SerializeField] private FirstScript ssilkaNaFirstScript;

 private void Die()
    {

        ssilkaNaFirstScript.ShowInterstitial();

    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question