W
W
WasTabon2021-04-03 16:04:20
C++ / C#
WasTabon, 2021-04-03 16:04:20

Why is an int from another class read as 0?

I have a random generation int ciAnd if you make output to the console in the same class, then it outputs normally, but if you receive it from another method, then it is always displayed as 0

public class Works : MonoBehaviour
}
    public int ci;
     public IEnumerator CourierWorkShopColor()
    {
        while (true)
        {
            System.Random r = new System.Random();
            ci = r.Next(0, coloredPrefabs.Length);
            Debug.Log(ci);
            spriteRendererSHOP.color = new Color32(prefabColor[ci].r, prefabColor[ci].g, prefabColor[ci].b, 255);
            yield return new WaitForSeconds(3.5f);
}


The same other method
public Works works;

private void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.CompareTag("Shop"))
        {
            Debug.Log(works.ci);
            if (gameObject.tag == works.ci.ToString())
            {
                allVariables.money += 5;
                works.howMuchEarn += 5;
                works.textMoneyCourierEarn.text = "Заработано - " + works.howMuchEarn;
                Destroy(gameObject);
            }

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