#hello

1 messages ยท Page 1 of 1 (latest)

minor bronze
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using UnityEngine.AdaptivePerformance.VisualScripting;

public class Pickup : MonoBehaviour
{
    public enum PickUpType
    {
        Toy
    }
    private int toysLeft, toysCollected, totalToys;
    public GameManager GM;

    //public TMPro.TextMeshProUGUI ToysText;

    public PickUpType Type;
    public int Value = 1;

    private void Start()
    {
        GameObject[] toys = GameObject.FindGameObjectsWithTag("Toys");
       // GameObject[] toys = GameObject.ta
        totalToys = toys.Length;
    }

    void Update()
    {
       // ToysText.text = GM.playerCharacter.Toy.ToString();
    }

    private void OnTriggerEnter(Collider other)
    {
        if(other.tag == "Player")
        {
            other.gameObject.GetComponent<Character>().PickUpItem(this);
            Destroy(gameObject);
            toysCollected++;
            if (toysCollected == totalToys)
                GM.GameIsFinished();

            //toysLeft = totalToys - toysCollected;
        }
        //ToysText = toysCollected.ToString();
    }
}
#

This code is on every toy that needs to be picked up

past dust
#

What on the UI does it update?

#

I don't see state changes here

minor bronze
past dust
minor bronze
#

script

#

they are updating the toy object on the HUD

past dust
#

Please post it on a paste site

wintry swiftBOT
minor bronze
#

this is the hud

#

sorry, I've never used a paste site before

#

The only line for the HUD update is in the Update function
The rest of it is all about the various popups

#
void Update()
    {
        ToysText.text = GM.playerCharacter.Toy.ToString();
    }

this is the line you want

#

But that's not all
I tried a different method too
I tried to make this same logic to work on the Toys script itself instead of a separate script
It worked perfectly in editor
but again, in the build, it won't work

#

I also have a timer on the right side in my HUD
Using almost the same lines of code for display but that works fine on the build...

#

I've also heard sometimes unity has a problem when tags are used

#

There must be a problem with the message not able to reach the UI or something
because we have a winner defined when he collects all toys in time, a popup appears, so when I checked if it was working, it is working

visual hull
#

I don't see anything obvious in this code that would break in a build vs the editor, so I would confirm that's actually what's happening

#

I can say that if your toysLeft and toysCollected variables are local to each pickup, that those values are not behaving how you're expecting them to

visual hull