- Home /
Trying to get Player Tip for player to open on Return and close on Return
Hi everyone, just trying to get this issue sorted. So I have a sign board that when the player clicks return a tip will pop up (i.e. "space to jump") and I want it so the player can just press enter again to close it. But if I try that, the menu opens and closes at the same time which is slightly annoying, any ideas?
private GameObject player;
private GameObject Tip1;
private GameObject Tip2;
private GameObject Canvas;
private GameObject TipObject;
private PlayerController playerScript;
public bool InTrigger = false;
public bool TipShowing = false;
// Use this for initialization
void Start () {
player = GameObject.FindGameObjectWithTag("Player");
Tip1 = GameObject.Find("TipPoint");
Tip2 = GameObject.Find("TipPoint2");
Tip1.SetActive(true);
Tip2.SetActive(false);
Canvas = GameObject.Find("WorldCanvas");
Canvas.SetActive(false);
TipObject = GameObject.Find("TipObject");
TipObject.SetActive(false);
playerScript = player.GetComponent<PlayerController>();
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Return) && (InTrigger == true && TipShowing == false))
{
playerScript.CanMove = false;
Debug.Log("Enter");
TipObject.SetActive(true);
Canvas.SetActive(false);
TipShowing = true;
}
if (Input.GetKeyDown(KeyCode.Return) && InTrigger == true && TipShowing == true)
{
Debug.Log("Enter2");
playerScript.CanMove = true;
TipObject.SetActive(false);
Canvas.SetActive(true);
TipShowing = false;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.tag == "Player")
{
Tip1.SetActive(false);
Tip2.SetActive(true);
Canvas.SetActive(true);
InTrigger = true;
}
Answer by Cyborg_X · Dec 28, 2018 at 04:26 PM
Solved this myself:
if (Input.GetKeyDown(KeyCode.Return) && InTrigger == true) { TipShowing = !TipShowing; //TipShowing being the actual tip after the intro Text (Press Enter) if (TipShowing == true) //If "Press Enter" is showing... { playerScript.CanMove = false; //player can't move //Debug.Log("Enter"); TipObject.SetActive(true); //Object containing the text is shown IntroCanvas.SetActive(false); //"Press Enter" is hidden } if (TipShowing == false) //Player presses enter again hence closing tip { //Debug.Log("Enter2"); playerScript.CanMove = true; TipObject.SetActive(false); IntroCanvas.SetActive(true); TipShowing = false;
Answer by Shreka · Aug 04, 2018 at 11:44 AM
use the tips on a diferent canvas or try to put all menu uis under a specific gameobject "menu" and disable it with a menu fuction code. and add tips under another game object eg "tip ui holder" and disable the tips. and then enable each tip with the script. sorry for mis types.
That's what I am doing but my problem is when I have the tip open by clicking 'Enter' I need to be able to close it again with enter - if that makes sense
Your answer
Follow this Question
Related Questions
Player Tips - Have triggers act independently 1 Answer
How do i make a one gun only Weapon system. (2D) 2 Answers
2D Flashlight for a platformer 2 Answers
Player stucken in the wall while jumping 2D 1 Answer
Double jump 2D Platformer 1 Answer