- Home /
i cant drag text to the inspector
I am making a game that needs a timer. I am very noob at scripting and unity. my problem is the text I want to use to the timer. I cant drag the text to the inspector
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public Text timerText;
private float startTime;
// Start is called before the first frame update
void Start()
{
startTime = Time.time;
}
// Update is called once per frame
void Update()
{
float t = Time.time - startTime;
string minutes = ((int)t / 60).ToString();
string seconds = (t % 60).ToString();
timerText.text = minutes + ":" + seconds;
}
}
i dont know if that pictrues help.
Answer by Bunny83 · May 09, 2020 at 01:20 PM
You are trying to assign the reference to the default reference of your script asset itself. Here you can only setup references to other assets. You can not assign any references to concrete objects in a scene.
Anyways in most cases you don't need / want to use the default references anyways. Attach your script to an actual object in your scene and assign the text instance to the variable on your script instance.
Default references are just an editor feature which allows you to specify certain default assets to be pre assigned whenever you attach that script to an object. This is a pure in-editor features. Default references have no effect at runtime at all.