Question by 
               Harardin · Aug 21, 2015 at 06:36 PM · 
                c#raycastcanvasscriptingbasics  
              
 
              Canvas Text show up but dont dissapear.
Hello everyone I want to create a canvas text that will show up when player looking on a intractable object. I made a script for it, it shows up text but don’t hide it when player doesn’t looking on a intractable object. Can some one please help me find where I made a mistake. Here is a Script.
 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class DoorRayCast : MonoBehaviour
 {
     public GameObject ePressText;
     public float RayDistanse = 3f;
     private float PhoneRayDistance = 3f;
     private float CeilingDistance = 5f;
     public phoneAnimationScript myphoneAnimationScript;
     public phoneAnimationScript myCharacterAnimationScript;
     public RelocateScript Relocate;
     Camera CameraMain;
     
    public void Start()
     {
         CameraMain = GetComponent<Camera>();
         ePressText.SetActive(false);
     }
     public void Update()
     {        
         RaycastHit hit;
         Ray ray = GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
         if (Physics.Raycast(ray, out hit, RayDistanse))
         {         
                 if (hit.transform.tag == "DoorTag")
                 {
                     ePressText.SetActive(true);
                     if (Input.GetButtonDown("actButton"))
                     {
                         hit.collider.GetComponent<DoorsActAnim>().DoorTrigger();
                     }
                 }
                 else
                 {
                     ePressText.SetActive(false);
                 }
             }
 }
 
               Thanks for your help.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by FortisVenaliter · Aug 21, 2015 at 06:42 PM
How about an else when the raycast does not hit anything?
Your answer
 
             Follow this Question
Related Questions
C# Touch Input with Raycast on Interactive Map to toggle Canvas 0 Answers
How can i draw line for word game 0 Answers
NullReferenceException: Object Reference not set to an instance of an object 0 Answers
wall check is always returning true even though the distance doesn't fit my parameters :( 1 Answer