Search Unity

make rawimage appear in trigger on button press help with code

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

  1. axobadzegiorgi5

    axobadzegiorgi5

    Joined:
    Jan 14, 2019
    Posts:
    3
    SignText assigned to RawImage that has to appear
    uiElement assigned to text telling player to press "e"
    but when i enter the trigger nothing happens at all, im quite new at unity so sorry if i sound dumb.
    and i do have 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. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
  3. axobadzegiorgi5

    axobadzegiorgi5

    Joined:
    Jan 14, 2019
    Posts:
    3
    thanks for attention but still nothing. looking back at it i dont know what could be wrong with the script everything looks fine to me.