Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Share
Go down
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 1093
Rep : 0
Join date : 2015-07-27
View user profile

OnCollision I wish text to be displayed.

on Mon Jul 27, 2015 9:17 am
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.
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 1096
Rep : 0
Join date : 2015-08-01
View user profile

Re: OnCollision I wish text to be displayed.

on Sat Aug 01, 2015 9:41 am
why don't you try using event trigger for UI.Text
Back to top
Permissions in this forum:
You cannot reply to topics in this forum