so i’m new at development, and i’m making a project that looks like “Flappy Bird”.
I put a collider between the two tubes and made it (is trigger), and wrote a script that add 1 point to the Score if the bird goes inside the hole.
the problem is: if I Duplicate this Object(that has the collider) the new one doesn’t work.
Here is the code,
Hope u understand my broken English:)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Scoring : MonoBehaviour
{
public Text scoreText;
public int scoreValue = 0;
public bool onTrigger = false;
// Start is called before the first frame update
void Start()
{
scoreText = GameObject.Find("Score").GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
scoreText.text = scoreValue.ToString();
}
void OnTriggerEnter2D(Collider2D other)
{
onTrigger = true;
scoreValue++;
}
void OnTriggerExit2D(Collider2D other)
{
onTrigger = false;
}
}
the “onTrigger” bool is just for testing so that I see if its works or not