Комментарии:
I can't drag the script into the canvas. NEED HELP PLS
Ответитьyour video is really great, it make our project for homework easy, thank you so much.
ОтветитьProbably a long shot but if anyone knows the answer lol - sometimes when my player collides with the coin (I just used a coin instead of fireflies), instead of adding +1 it adds +2. Is this because it's detecting multiple collisions for some reason? If so, how do I prevent that? Thanks!
ОтветитьYour videos are extremely helpful! Thank you!
Ответитьvery useful information to call some things from other scripts into the one u are working on, thanks!!!
ОтветитьWhen I pick up my score object, it sometimes gets collected multiple times. Any idea why this might be? There's no duplicate object behind it, there's only 1 rigidbody/collider on my player.
ОтветитьI have a question about the score variable, doesn't it also work if I use getters and setters instead of making the variable public?
ОтветитьAbsolute Garbage. Using Unity 2021.3.11f1 and the text can't be dragged on to the public object in the script.
ОтветитьFor me it says "Object refrence not set to an instance of an object" how do I fix this? I did what you did in the video but got this messege when trying to collect my "fireflys" :)
Ответитьthis was so helpful!!!!!!!!!!!!!!!!
Ответить(EDIT TO VIDEO)
Someone pointed out to me that if you update your UI using the Update() method, then you risk garbage collection happening. Which basically means the UI gets updated unnecessarily each frame, even if no changes happens to the UI. 🙂 And this might impact your games performance if you have a lot of it going on.
So here is a fix to make sure the UI only gets updated IF any changes to it has happened:
👾SCOREMANAGER CHANGES👾
public class ScoreManager : MonoBehaviour
{
private int scoreLast; // NEW FIELD THAT CHECKS IF SCORE HAS CHANGED 👈
public TMP_Text textScore;
public int score = 0; // CHANGE THE FIELD TYPE TO INT 👈
// Start is called before the first frame update
void Start()
{
textScore.text = score.ToString() + " FIREFLIES";
}
// Update is called once per frame
void Update()
{
if(scoreLast != score) // IF STATEMENT THAT CHECKS IF SCORE HAS CHANGED👈
{
textScore.text = score.ToString() + " FIREFLIES";
}
}
}
👾FIREFLYCONTROLLER CHANGES👾
public class FireflyController : MonoBehaviour
{
private ScoreManager scoreManager;
private void Start()
{
scoreManager = GameObject.Find("Canvas").GetComponent<ScoreManager>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
scoreManager.score += 1; // REMOVE THE "f" SINCE IT IS NO LONGER A FLOAT 👈
scoreManager.scoreLast = scoreManager.score; // UPDATES THE scoreLast FIELD 👈
Destroy(gameObject);
}
}
}
Are u going to continue the c# series?.. i just finished them and i learned so much so quickly but I m now sad knowing that you haven't done any more videos.
ОтветитьWhy do this guy look like Elon Musk
ОтветитьYou are highly underrated my friend ...
ОтветитьThanks. I like your explanations. :)
ОтветитьNever expected you to create a Unity tutorial! You are truly multi talented!
Ответитьmy useless comment for engagement
Ответитьfirst
Ответить