I am using GetKey and GetKeyDown to cast a spell, and then adjust my Magic Power in text on the screen.
The only problem is, the Text does change, however only as the key is pressed down then reverts to my default text. How do I get my text to stick with the adjustments?
If you’re updating the text in your update method, it will change it back as soon as the key is no longer being pressed, an example of this would be like:
void Update(){
myText.text = "normal text";
if(Input.GetKey(KeyCode.E)){
myText.text = "pressed text";
}
}
If you want to prevent this, only update the text when a key is pressed, and I suggest you set it in the start method so it isn’t empty to begin with.
void Start(){
myText.text = "normal text";
}
void Update(){
if(Input.GetKey(KeyCode.E)){
myText.text = "pressed text";
}
}
Edit: sorry for the bad code formatting lol.