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

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » OnCollision I wish text to be displayed.

OnCollision I wish text to be displayed.

View previous topic View next topic Go down  Message [Page 1 of 1]

1 OnCollision I wish text to be displayed. on Mon Jul 27, 2015 9:17 am

darius0995


Member [Lv. 0]
Member [Lv. 0]
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.

View user profile

2 Re: OnCollision I wish text to be displayed. on Sat Aug 01, 2015 9:41 am

demons


Member [Lv. 0]
Member [Lv. 0]
why don't you try using event trigger for UI.Text

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum