#hello
1 messages ยท Page 1 of 1 (latest)
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
oh dear my game manager ui file is too big to paste here
You can use a paste site
https://hatebin.com/
yes they are on the game manager ui
script
they are updating the toy object on the HUD
Please post it on a paste site
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
this is the hud
https://hatebin.com/jolcmjtdqn
is this what you want??
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
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
yep, if this is the line that matters, what is GM.playerCharacter.Toy and where is it set?