score system
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class score : MonoBehaviour {
public int scoreValue;
public Text scoretext;
// Use this for initialization
void Start () {
scoreValue = 0;
}
// Update is called once per frame
void Update () {
scoretext.text = scoreValue.ToString();
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.tag == "ball")
{
scoreValue = scoreValue +1;
}
}
}
as you can its a very simple score system ,so what i am trying to achieve her is my ball fall into a bucket with a triger collider soo the bucket is a prefab and the ball is a prefab too these too prefabs are being used many time over and over again ,buckets move below the screen like the pipe in flappy bird,as these are prefab , as i said the bucket is a prefab which randomly generating like the pipes in flappy bird, so after creating my score system i drag and drop the text ui into the given place ,and i apply the changes and delete that prefab and when i go back to asset and check that prefab the given place for text says none.so how can i link the text ui directly to the script so it wont delete it self.
and i have a nullrefrenceexception error in my void update function and i think this error means the same .but i cant figure out how to fix this can some one guide me to the right tutorial or tell me what i am doing wrong here
Closing as duplicate but I've put an answer in the other question.
Follow this Question
Related Questions
Movement Unit (RTS) 0 Answers
Car from Unity's standard assets giving me of null reference errors 0 Answers
How do I resolve, get_isActiveAndEnabled can only be called from the main thread error 1 Answer
Spawn added objects into a circle 1 Answer
How do you move the camera with the player. Whats wrong with my code? 0 Answers