Search Unity

i cant make RawImage or text appear in trigger

Discussion in 'Scripting' started by axobadzegiorgi5, Jan 15, 2019.

  1. axobadzegiorgi5

    axobadzegiorgi5

    Joined:
    Jan 14, 2019
    Posts:
    3
    i want it so when my player goes in trigger the text will display and when the player presses "E" the text disappears and RawImage appears, but when the player enters the trigger nothing seems to happen and i dont know whats wrong with my script. someone help. (i have the FPScontroller in Players tag) :(


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ShowText_OnKeyPress : MonoBehaviour {
    6. [SerializeField] private GameObject SignText;
    7. [SerializeField] private GameObject uiElement;
    8.  
    9. void OnTriggerStay(Collider other)
    10. {
    11. if (other.CompareTag ("Player"))
    12. {
    13. uiElement.SetActive (true);
    14.  
    15. if (Input.GetKeyDown (KeyCode.E))
    16. {
    17. SignText.SetActive(true);
    18. uiElement.SetActive(false);
    19. }
    20.  
    21. }
    22. }
    23.  
    24. private void OnTriggerExit(Collider other)
    25. {
    26. if (other.CompareTag ("Player"))
    27. {
    28. uiElement.SetActive(false);
    29. SignText.SetActive(false);
    30. }
    31. }
    32. }
    33.  
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    You've put your script on the gameObject that has the trigger collider on it? You're sure the player's collider gameObject has tag "Player"?

    This is where you want to tease apart the potential causes and narrow it down. Add some Debug.Log statements to OnTriggerStay, to see what's within the trigger bounds. See if it's triggering at all. Then see what the Tag is of the thing that triggered it, etc. Maybe you're getting errors because uiElement is null? (It's not clear how you're assigning a value to uiElement.)