K
K
KurwaTM2021-04-26 16:00:00
C++ / C#
KurwaTM, 2021-04-26 16:00:00

How can I pass a value from another script to another script?

I have 2 scripts. The first PlayerLogic is responsible for the logic (hp, damage, etc.). The second PlayerUI is a GUI script. In the first script, for example, there is public int health = 100; and in the second I want to pass the value of health to display hp on the GUI; How can I do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KurwaTM, 2021-04-26
@KurwaTM

Found!
Here is the script:
1.cs: 2.cs:
public static int health = 100;

public GameObject go;
    public PlayerLogic PlayerLogic;

    private int health;
    void Start()
    {
        PlayerLogic = go.GetComponent<PlayerLogic>();
    }

    void Update()
    {
        health = PlayerLogic.health;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question