In this video we'll see how to access from a script to a method that is defined in another script in Unity.
How to use functions that are in another Script:
1. We start with 2 scripts A and B. In A Script is the function we want to call. In B Script we will call the function that is in A.
2. In A Script we make sure that the function or method is declared as public, otherwise we will not be able to access it from an external context to A.
3. In B script we declare an object of A type and we must find the reference of that object. This will depend on where we are programming, in the case of Unity we will do it in the Start method, with the instruction GameObject.FindGameObjectWithTag() and to that GameObject we execute the GetComponent method. The final instruction looks like this:
a=GameObject.FindGameObjectWithTag().GetComponent{A}(); //(replace the curly brackets with the signs less than and greater than).
4. To call the function of the other A Script from B, we use the A reference that we define and with the dot operator we can access that function and use it inside the B Script.
____________________________________________________________
LINKS
Portfolio: https://gamedevtraum.com/en/portfolio...
LinkedIn: / gamedevtraum
Downloads: https://gamedevtraum.itch.io/
Contact: / gamedevtraum
____________________________________________________________
#EN
En esta página del sitio puede ver el video en línea How to call a FUNCTION FROM A DIFFERENT SCRIPT in Unity de Duración hora minuto segunda en buena calidad , que subió el usuario GDT Solutions ES 30 mayo 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 71,889 veces y le gustó 655 a los espectadores. Disfruta viendo!