UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


descriptionOnCollision I wish text to be displayed. EmptyOnCollision I wish text to be displayed.

more_horiz
Basicially, when a collision occurs I wish for my UI text to be displayed. Here is the method I am using to accomplish this, the script is attached to my UI Text GameObject:

Code:

using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
public class text : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
          
        GetComponent<Text>().enabled = false;
 
     }
    
    
        
 
        
    void OnCollisionEnter2D(Collision2D Man)
         {
            if (Man.gameObject.tag == "house")
                 GetComponent<Text>().enabled = true;
            
         }
 
  }
 
 


Within Void Start I can successfully enable and disable the UI Text, however within the OnCollisionEnter2D, the GetComponent<Text>().enabled = true; just doesn't get recognised when a collision is made and so the text doesn't become true (doesn't show). I can confirm that a collision is detected, so that's not the problem.. I suspect it's something to do with the .enabled method? Could somebody help me with this.

descriptionOnCollision I wish text to be displayed. EmptyRe: OnCollision I wish text to be displayed.

more_horiz
why don't you try using event trigger for UI.Text
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply