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
0
Question by Samillennium · Dec 20, 2016 at 07:48 AM · uicanvasboxdialogue

Dialogue box wont show in game unless it's in the canvas but...

Okay so, My games dialogue box wont show on the window unless I drag it into the canvas, problem with that being is the dialogue box will show upon starting up the game when I hit play . How do I get this thing to only appear when the user presses the space bar down near the box? https://youtu.be/SnA0uYLi5dU Here's a video of my problem so you can see first hand what I am dealing with

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ForeignGod · Dec 20, 2016 at 10:04 AM

Keep the button in the canvas and disable it.

Add this script to a gameobject in the scene.

 var yourButton : GameObject;

 function Update (){
     if(Input(GetKey(KeyCode.Space))
     {
         yourButton.SetActive (true);
     }
 }

Another good practice is to keep your game window to your desired build resolution/aspect ratio. This makes it much easier to design and place your UI elements.

Take a look at anchoring UI elements.

https://docs.unity3d.com/Manual/UIBasicLayout.html

Comment
Add comment · Show 2 · 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 Samillennium · Dec 20, 2016 at 06:13 PM 0
Share

I'm sorry I'm probably doing this wrong could you have a look and see if I messed it up? alt text

prolly-doing-this-wrong.png (108.7 kB)
avatar image ForeignGod Samillennium · Jan 03, 2017 at 09:11 AM 0
Share

Sorry for a late answer, but my code was in unityscript, you could convert it or just create a new .js script :)

avatar image
0

Answer by PizzaPie · Jan 03, 2017 at 02:01 PM

 public class OpenDialog : MonoBehaviour
 {
     public GameObject boxDialogue;
     public Transform player;
 
     bool isActive;
     public float someValue;
 
     void Update()
     {
         if (Input.GetKey("space"))
         {
             float dist = Vector3.Distance(player.position, gameObject.transform.position);
             if (!isActive && dist < someValue)
             {
                 isActive = !isActive;
                 boxDialogue.SetActive(isActive);
             }
             else if(isActive)
             {
                 isActive = !isActive;
                 boxDialogue.SetActive(isActive);
             }
         }
     }
 }
 
 

Attach that script to the box. Set the references on the inspector ,also set the someValue. It should work if i didn't mess with the if conditions. There are other ways to check if it is close to the box that is up to you

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

6 People are following this question.

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

Related Questions

Interacting with sign, canvas lags when activating. 0 Answers

UI menu not rendering properly 1 Answer

Unity Android Screen Glitch 1 Answer

[Video]Strange UI Behaviour, possible bug? 0 Answers

2D Collider Isnt working 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