How do I inactivate Text in a script?
I am trying to have my text only activate once I press x but the only problem is Idk how to inactivate a text in script but I see it's possible in the scene screen. Help?
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class PlayerMovement : MonoBehaviour {
public float speed;
private int count;
private Rigidbody rb;
public Text countText;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
countText.text = "Count = " + count.ToString();
SetCountText();
}
void Update()
{
if (Input.GetKeyDown("x"))
{
//Put script suggestion in here
}
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("PickUp"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText ()
{
countText.text = "Count:" + count.ToString();
}
}
Answer by UnityCoach · Dec 07, 2016 at 01:55 PM
Did you try this?
countText.enabled = false;
Answer by dragonking300 · Dec 07, 2016 at 03:02 PM
.-. , if only Ik .enabled was a thing
it works with every component that can be enabled/disabled. ;)
Haha, I think he made a joke using the Dutch form of "me" being "ik". Implying
me.enabled = true;
being useful if that was possible in real life.
Eh, I just learnt some Dutch! :) Thanks! (Sorry for the misunderstanding)
Your answer
Follow this Question
Related Questions
How can i run a script with a single key press? 1 Answer
Having transitions between two VideoPlayers triggered by clicking "x" times in a text layer 0 Answers
How to add a editing option to variables in a script in Inspector? 0 Answers
How to make a random object generator that responds to simple touch? 0 Answers