A
A
Alexander2020-07-24 17:31:14
Unity
Alexander, 2020-07-24 17:31:14

How to call a method from another script?

First (snippet):

public int hp = 100;
  public int hpMax = 100;

  void Update()
  {

    if (hp > hpMax)
    {
      hp = hpMax;
    }

    if (hp <= 0)
    {
      Die();
    }
  }

  public void Hit(int damage)     //хочу вызвать во втором скрипте, дабы обьекту с тегом и этим скриптом был нанесен урон
  {
    hp -= damage;
  }

Second (snippet):
if (hit.transform.CompareTag("Gas tank"))
       {

       }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question