Y
Y
yraiv2020-05-11 14:10:52
Unity
yraiv, 2020-05-11 14:10:52

How to load the value of a variable into another script on another object?

I understand how to take the value of a variable from another script on another object, but how can I return it there? for example, I have an object, when the object runs out of life, then I need it to add the money that is due for the destruction of the monster to the amount of money that is stored in a separate script on another object.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ClickOnMonstr : MonoBehaviour
{
    public int Hp;
    public int MoneyMonstr;
    public int Damage;
    public GameObject BalanceGive;
    public Balance BalanceScript;

    private void Start()
    {
        
        BalanceScript = BalanceGive.GetComponent<Balance>();


    }
    public void OnMouseDown()
    {
        if (Hp >= 1)
        {
            Hp = Hp - Damage;

        if (Hp < 1)
            { 
                BalanceScript.Money = BalanceScript.Money + MoneyMonstr; // вот тут косяк
                Hp = 3;
            }
        }
    }
    

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DanielMcRon, 2020-05-11
@yraiv

In the same way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question