C
C#2y ago
cuhpl

❔ Hi,my flappy bird game script isnt working

The script in making is to show that the score counter incrreases when the gamobject(bird) collides with the trigger inbetween the pipes but it isnt working can someone check if its my script that is wrong or idk using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class logic : MonoBehaviour { public int playerscore; public Text score; [ContextMenu("IncreaseScore")] public void addScore() { playerscore = playerscore + 1; score.text = playerscore.ToString(); } } this script is to increase the score using System.Collections; using System.Collections.Generic; using UnityEngine; public class middlescript : MonoBehaviour { public logic logic; // Start is called before the first frame update void Start() { logic = GameObject.FindGameObjectWithTag("logic").GetComponent<logic>(); } // Update is called once per frame void Update() { } private void OnTriggerEnter2D(Collider2D collision) { logic.addScore(); } } this script is to communitcate to the script above and to add score whenever the gameobject collides with the trigger
7 Replies
Zendist
Zendist2y ago
Have you tried adding a debug log message to the OnTriggerEnter2D? To see if the collision ever occurs.
.tosi.
.tosi.2y ago
instead of playerscore = playerscore + 1 you can just have playerscore+=1 instead of public int playerscore you gotta have public int static playerscore
TheRanger
TheRanger2y ago
no need of static score if you only have 1 instance of logic try reading the description of TriggerEnter u might know why it isnt working
TheRanger
TheRanger2y ago
iirc, this has to be checked in order for triggerenter2d method to work
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts