Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ImNewAtThis · Mar 04, 2016 at 12:25 PM · unity 5guibuttontriggervisibility

How do i make a button appear when my FPSController walks through a tigger collider?

I followed a tutorial to make UI text appear over an object when I enter a cube collider and disappear when I exit, is there a way to make the same thing happen with a UI button? The button is supposed to open a window with information on the object and a short turnaround video. I'm using the standard FPSController with an Xbox Gamepad as input. Will i still be able to "click" the button by pressing A if i haven't got a mouse cursor to hover over the button?

Below is the code from the tutorial to make the UI text appear. I'm fairly new to coding in general, working in C#.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class fadeEffects : MonoBehaviour {
 
     public string myString;
     public Text myText;
     public float fadeTime;
     public bool displayInfo;
 
     void Start ()
     {
         myText = GameObject.Find("Text").GetComponent<Text>();
         myText.color = Color.clear;
 
     }
 
     void Update ()
     {
         FadeText();
 
      
     }
 
     void OnTriggerEnter ()
     {
         displayInfo = true;
     }
 
     void OnTriggerExit ()
     {
         displayInfo = false;
     }
 
     void FadeText ()
 
     {
         if(displayInfo)
         {
             myText.text = myString;
             myText.color = Color.Lerp(myText.color, Color.white, fadeTime * Time.deltaTime);
             
 
         }
 
         else
         {
             myText.color = Color.Lerp(myText.color, Color.clear, fadeTime * Time.deltaTime);
         }
 
     }
     
    
 }



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aditya · Mar 05, 2016 at 07:57 AM

  using UnityEngine;
  using UnityEngine.UI;
  using System.Collections;
  
  public class fadeEffects : MonoBehaviour {
     public Button btn;
 
     void Start(){
         btn = Gameobject.Find("Button").GetComponent<Button>();
     }
 
     void OnTriggerEnter(Collider other){
         if(other.gameObject.tag == "THE TAG OF GAMEOBJECT THE TRIGGER IS SEARCHING FOR"){
             btn.gameObject.Setctive(true);
         }
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ImNewAtThis · Mar 10, 2016 at 11:30 AM 0
Share

Thanks, I'll give this a try too

avatar image
0

Answer by Exceptione · Mar 06, 2016 at 11:26 AM

Hey @AaronDiscProg !

Take a look at the documentation for trigger callbacks: http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

(If you're using MonoDevelop, you can put the cursor on any method/variable name and press Ctrl+' to bring up the documentation!)

The methods need to take a parameter, to make sure they're being called, you can also write Debug.Log("Here!"); inside the functions to verify.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ImNewAtThis · Mar 10, 2016 at 11:29 AM 0
Share

Thanks, I'll take a look at that documentation now

avatar image
0

Answer by danidu93 · Mar 05, 2016 at 01:00 AM

Hi, 1st of all declare a button and give it a name in your script Button MyButton;. Second you have to atach it to a game object as you did for the text :
myText = GameObject.Find("Text").GetComponent<Text>(); I precise that if your object is inside a canvas you have to write all the URL for example:

"myText=GameObject.Find("Canvas/Text")...."


Now to enable a game object you have to write this code :

 MyButton.gameObject.SetActive(true); // this is for enable
 
 // if you want to disable it write this code
 
 MyButton.gameObject.SetActive(false);

For your condition i cannot help you i don't know how to use colliders but there is alot of tutorial on the web . I hope this will help you and sorry for my bad english @AaronDiscProg

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ImNewAtThis · Mar 10, 2016 at 11:30 AM 0
Share

Thank you, I'll give this a try

avatar image
0

Answer by ImNewAtThis · Mar 15, 2016 at 08:50 PM

Figured it out, thanks for the replies. In the end I made the button a child of an image and then i was able to fade the image from clear to visible as the character entered a collision trigger. The complicated part was making it clickable when selected and joystick button 0 is pressed. i have a temporary fix for that but I'm working on a better method, the current method disrupts the "first selected" option on the event system.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to trigger a button click from script 3 Answers

How to instantiate a prefab between Canvas and a Button? 0 Answers

UI button doesn't appear - c# 3 Answers

Button back not clickable after rotation animation 1 Answer

Unity 5 GUI system 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges