❔ Hi,my flappy bird game script isnt working

CCuhpl2/11/2023
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
ZZendist2/11/2023
Have you tried adding a debug log message to the OnTriggerEnter2D? To see if the collision ever occurs.
Ttosi2/11/2023
instead of playerscore = playerscore + 1 you can just have playerscore+=1
Ttosi2/11/2023
instead of public int playerscore you gotta have public int static playerscore
TTheRanger2/11/2023
no need of static score if you only have 1 instance of logic
TTheRanger2/11/2023
try reading the description of TriggerEnter u might know why it isnt working
TTheRanger2/11/2023
TTheRanger2/11/2023
iirc, this has to be checked in order for triggerenter2d method to work
Image
AAccord2/12/2023
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.