- Home /
Can't drag text object into inspector?
I have this code written to increase my score when I destroy an enemy, but whenever I try to drag the text object into the inspector so that it can actually be affected by the script, I am unable to. I just get a circle with line through it and it won't go into the public text spot I've made for it. It also does not appear if I click the little select circle next to the spot in the inspector. I'm just using the regular UI text object, I have no idea what the problem is. Here's the code, if it's any help:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Enemy01 : MonoBehaviour {
public float speed = 2f;
public float health = 7;
public Text score;
private int count;
void Start () {
count = 0;
SetCount ();
}
void Update () {
Vector2 position = transform.position;
position = new Vector2 (position.x, position.y - speed * Time.deltaTime);
transform.position = position;
Vector2 min = Camera.main.ViewportToWorldPoint (new Vector2 (0, 0));
if (transform.position.y < min.y) {
Destroy (gameObject);
}
}
void OnCollisionEnter2D(Collision2D other){
if (other.gameObject.tag == "Projectile") {
health -= 1;
if (health <= 0){
Destroy (this.gameObject);
count = count + 100;
SetCount();
}
}
if (other.gameObject.tag == "Flag") {
Destroy (this.gameObject);
}
}
void SetCount(){
score.text = count.ToString ();
}
}
Any help would be massively appreciated.
Your answer
Follow this Question
Related Questions
How can i link my code together so the score value affects the timer value 1 Answer
TextMeshPro Not updating Text with Rich Tags Immediately 1 Answer
Problems exposing 4.6 Text to the inspector as public Text 1 Answer
Display the same string in multiple text boxes 1 Answer
Need help with adding score from 2 different script C# 4 Answers