Somehow i get this error if i want to change text onmousedown: Object reference not set to an instance of an object
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class stealRam : MonoBehaviour {
public Text txtRef;
private void Awake()
{
txtRef = GetComponent();
}
void OnMouseDown() {
txtRef.text = “Ram aqquired”;
}
}
public class stealRam : MonoBehaviour {
public Text txtRef;
private void Awake() {
txtRef = GetComponent(typeof(Text)) as Text; // <-- provide the type of component you are getting from the gameObject to which this script will be attached. Make sure the Text is indeed attached to that gameObject in unity's inspector. Otherwise, GetComponent won't be able to "establish a link" to it
}
void OnMouseDown() {
txtRef.text = "Ram aqquired";
}
}