How to pass variables between scripts, 2 methods- UNITY Basics

preview_player
Показать описание
An example of how you can pass variables between two scripts in Unity. There's a few ways you can do this, but this is a couple of examples of two basic ways that can be used in a wide range of scenarios.
Рекомендации по теме
Комментарии
Автор

thank you man i was trying to do this for 1 hour

RodrigoSilvinoDutra
Автор

This is basically the only video I faound that solves the problem in a comprehensive way! Thank you!

armerrttr
Автор

its not working for me...
these are my two scripts:

public class ScoreManagement : MonoBehaviour
{
public int score;

public void Update (int value)
{
score + value;
}
}

and:

public class Coin : MonoBehaviour
{
public int value;

public void Update ()
{

}

public void OnTriggerEnter2D(Collider2D other)
{

{
Destroy(gameObject);
}
}
}

Please send help

jonathanbraun
Автор

damn mine wont work, I've followed 3 tutorials now and matched them exactly idk tf is wrong...

shadowsnake
Автор

So where is the hit button located that you click on. Is it in the Canvas?

anythingpeteives
Автор

It can't be as simple as creating new object and getting the value, but must know exact function to find objects.

Netryon
Автор

thanks it helped me a lot....!!!! gonna have a good sleep now.

nitishvarun
Автор

Don't trust this tutorial! he's not using dark mode in Visual studio! 😉

nickwilson