Question by
opritaoctav · Oct 04, 2021 at 08:58 PM ·
uitextscorescore systemcopy-paste
UI text script working on an object but not working on copied object
So I'm trying to make flappy bird copy. And everything went well and nicely. And now I'm to the UI (counting the score). So between the pipes, I add an empty game object with a box collider2d set on trigger with this script attached to it (^1 first script), and when canMove == false
(which indicates if I die, ^2 second script) I reset the score to zero. This work well so far. But when I try to copy and paste the game object(to put it furthermore in the level) the score doesn't update. This is the last piece in order for me to finish the game and I'm really stuck... Thanks in advance. script1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class scoreCalculator : MonoBehaviour
{
public int score;
public Text count;
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "player")
{
score++;
count.text = score.ToString();
}
}
private void Update()
{
if(deathRespawn.canMove == false)
{
score = 0;
count.text = score.ToString();
}
}
}
script2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class deathRespawn : MonoBehaviour
{
public GameObject player;
public Transform spawnPoint;
public Rigidbody2D rb;
public static bool canMove = true;
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "player")
{
player.transform.position = spawnPoint.transform.position;
rb.velocity = new Vector2(0, 0);
canMove = false;
}
}
}
and some images
unityquestion1.png
(13.9 kB)
unityquestion2.png
(64.6 kB)
Comment