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 /
  • Help Room /
avatar image
0
Question by bokchoy4221 · Jun 14, 2016 at 07:31 AM · uibuttontextpopup

Popup text in certain area when clicked

Hi guys,

I am completely new to Unity and would like some help.

I am trying to make a script / action in C# where if a button is clicked a text will appear for about 0.5 seconds within a certain area and then disappear.

Are you able to point me to the right direction or possibly give me a step by step guide on what to write? or a code with //comments above that i can follow and understand what is going on.

Thanks

Comment
Add comment · Show 16
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 Mmmpies · Jun 14, 2016 at 10:18 AM 0
Share

That's a really generalised question, and very little to go on but what you need is to follow some of the tutorials.

https://unity3d.com/learn/tutorials/topics/user-interface-ui

Chances are you'll be able to do it yourself after following a few of them (and actually working along with them) but if not you can come back with a more specific question.

The tutorials are really good.

avatar image bokchoy4221 Mmmpies · Jun 14, 2016 at 10:43 AM 0
Share

alt text *White = Size of Screen *Blue = Area of which pop up text should come up only

Hi, thanks for the response. Hopefully this picture that i drew can clear it up.

  1. user clicks on button

  2. "pop up message" appears in the blue area and disappears after set amount of time

so i think i need something like this on the button

 void Update () {
 if (GetButtonDown("Fire1"))
 {
 //Code that instantiates my text into the the blue area with a random position
 }
 }

avatar image bokchoy4221 · Jun 14, 2016 at 11:43 AM 0
Share

I tried this. When i click the button i can see anew Text(Clone) spawn but even though it has Text within the body it does not show.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class OnClick : $$anonymous$$onoBehaviour {
 
     public Text popUP;
     private Vector2 position = new Vector2(0,5);
 
     public void PopUP ()
 
              {
             Instantiate(popUP, position, Quaternion.identity);
         }
     
 }
avatar image EpiFouloux bokchoy4221 · Jun 14, 2016 at 12:37 PM 0
Share

If it's a Text, you need to put him child of a Canvas :

public GameObject canvas

popup.transform.setParent(canvas)

avatar image bokchoy4221 EpiFouloux · Jun 15, 2016 at 05:02 AM 0
Share

i get error

Cannot convert from UnityEngine.GameObject to UnityEngine.Transform

Show more comments
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by EpiFouloux · Jun 14, 2016 at 10:53 AM

EDITED Well try something this way:

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using System;
    
    public class OnClick : MonoBehaviour {
    
        public GameObject popUP; // prefab to instantiate
        public Canvas canvas; // father canvas
        private Vector2 position = new Vector2(0,0);

        void Start()
         {
                position.x = Random.Range(-10f, 10f);
                position.y = Random.Range(-10f, 10f);
          }
    
        public void PopUP ()
    
            {
                GameObject inst = (GameObject) Instantiate(popup, position, Quaternion.identity);
                inst.transform.SetParent(canvas.transform);
                Destroy(inst, 1.0f);
            }
  }

Your button must have this script linked and activate the Popup function.

Comment
Add comment · Show 4 · 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 Mmmpies · Jun 14, 2016 at 11:24 AM 0
Share

You'll need

 using UnityEngine.UI;

rather than import for C#

avatar image EpiFouloux Mmmpies · Jun 14, 2016 at 12:35 PM 0
Share

thanks I correct it :P

avatar image bokchoy4221 EpiFouloux · Jun 16, 2016 at 09:30 AM 0
Share

I currently have 2 Canvases, Canvas 1 that i was unable to change the size of (the parent canvas) and a child canvas 2 where i can change the size, which is inside Canvas 1 (the child canvas).

I tried

         position.x = Random.Range(-Screen.maxwidth, Screen.maxwidth);
         position.y = Random.Range(-Screen.maxheight, Screen.maxheight);

but the "pop up texts" go all over the place ins$$anonymous$$d of just Canvas 2

Show more comments

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

80 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI Text Editing Problem, What's Wrong? Need Anybody to Assist 1 Answer

How to disable button text UI 0 Answers

Problem with highlighting correct answer, any idea? 1 Answer

UI text wont highlight 0 Answers

How do I change UI button background AND button text on click(pressed)? 0 Answers


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