Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Mr B · May 19, 2015 at 10:11 AM · uibuttonunity5canvas

How to make a UI Canvas not appear again after the first time the user hits the "I Agree" button.

In my app, I have a disclaimer. After the user hits the "I Agree" button, the disclaimer disappears. What I want is, that the user only has to press that button once, in the app's lifetime in his/her device. After the user agrees, the user will not see that disclaimer again. Meaning (forgive me if I am redundant) that, the user does not have to press the button (agree) every time he/she opens the app. Also after the game object is destroyed, I want to see the changes in the editor; in another script (because when the game object is destroyed you can't see it's inspector). This is the last part of the development of this app. The app is written in C#. Any help will be greatly appreciated.

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
2

Answer by applemaniac · May 19, 2015 at 10:48 AM

What you need is a global memory, to memorize if the user accepted your thing. You could use PlayerPrefs :

 if (PlayerPrefs.GetString("accepted")=="true")
 ///Disable your canvas
 
 if(///The player accepts)
  PlayerPrefs.SetString("accepted", "true");

And you can still use your PlayerPref at any moment to know the changes.

Comment
Add comment · Show 5 · 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 Mr B · May 20, 2015 at 04:49 AM 0
Share

$$anonymous$$uch appreciated applemaniac. The response was way too fast and very accurate. I feel like giving this simple, but useful code to the community. I searched for it in Unity Answers and found absolutely nothing specific, regarding how to make a one time disclaimer. So I will write a (SOLUTION) thread, that will read exactly like this: How to make a one time disclaimer. (SOLUTION) And of course, I will give you credit for it. Again, thanks for the time and attention you put in answering my question.

avatar image applemaniac · May 20, 2015 at 06:00 AM 0
Share

Well, my pleasure :)

avatar image Mr B · May 27, 2015 at 07:04 PM 0
Share

The name was changed to How to make a one time disclaimer. (C# SCRIPT) Here is the link

avatar image Mr B · May 28, 2015 at 05:59 PM 0
Share

Since an ad$$anonymous$$ is fixed on rejecting posts without leaving a reason in a comment, like it is stated in the ad$$anonymous$$ guidelines for rejecting a post I am posting this here then.

Thanks to applemaniac, who demonstrated how to use PlayerPrefs, in a very accurate manner, and a very short notice.

TWO THINGS TO RE$$anonymous$$E$$anonymous$$BER:

  1. The Application.Quit function is ignored in the editor. Test in the actual device.

  2. Once you have tested the "one time property" of the script, you have to reset the script. So you can build the application with the disclaimer intact. In other words, there is no point in having a disclaimer, if the user will never see it, because you built the application with the disclaimer destroyed by yourself in the editor.

  3. The "print" is there so you can see in the console, that the script worked. When the game object is destroyed, the inspector cannot display the contents of the object, because it is not there.

HOW TO RESET THE SCRIPT:

In UserAgrees() and Start(), set the int to 2. Save your script and return to Unity. Save your scene if you want and hit play. You will see your disclaimer is back. This is because the value used to destroy the disclaimer is a new one, and has not been met as a condition. Hit the "I Agree" button so the int (2) is saved. Return to your script, set the int to 1 again. Save your script and return to Unity. Now when you build, the disclaimer will be there in all the distributions of your app, because in each individual download, the condition used to destroy the disclaimer is yet to be met. I used the 2 only to demonstrate. You can just change the 1 to 2 and then build. Also I would like a "disclaimer" tag so it is even easier to find this answer. If a mod would be so kind to make one, I would appreciate it.

avatar image Mr B · May 28, 2015 at 06:03 PM 0
Share
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class DisclaimerController : $$anonymous$$onoBehaviour
 {
 
     public GameObject Disclaimer;
 
     public Button iAgree;
     public Button iDontAgree;
 
 
     public void UserDoesNotAgree()
     {
         Application.Quit();
     }
 
     public void UserAgrees()
     {
         PlayerPrefs.SetInt ("accepted", 1);
         Destroy (Disclaimer);
     }
 
     void Start ()
     {
         if (PlayerPrefs.GetInt ("accepted") == 1)
         {
             Destroy (Disclaimer);
             print(PlayerPrefs.GetInt("accepted"));
         }
     }
 
 }
avatar image
0

Answer by anisharya16 · Jan 25, 2020 at 06:01 AM

I have the same problem, I created another canvas where i want to display game updates features. But that canvas does not shows up. I tries using "Sort Order" to 0 and 1 resp. but the new canvas does not shows up. How to solve this?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UI elements are not getting affected by lighting 0 Answers

Strange UI Button hover offset when using Worldspace Canvas in VR 4 Answers

Set Native Size in UI 1 Answer

My UI buttons work fine in editor but when I exported the game on Android, only some of them works. 0 Answers

Moving a button out of screen in iPhone 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