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 Raikir-i-sh · Aug 24, 2020 at 12:41 PM · scalechangeinterpolation

[Solved] How do you Scale 0 to 1 by a button and reverse back when btn is pressed again?

I wanted to make a shop UI . So when I pressed " I " , it should activate shop UI and scale it from 0 to 1. And when I close it, it should scale back down to 0. I searched in youtube and googled it but couldn't find a satisfying one.

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
0
Best Answer

Answer by sacredgeometry · Aug 24, 2020 at 12:45 PM

So you could use a boolean to store the state and every time the button click event gets triggered you switch the state of bool i.e. myBool = !myBool.


This will swap it to true if false and false if true.


From there you can either cast it directly to an integer (which will result in 1 for true and 0 for false), use the bool to determine or set the integer value or simply switch on the bool. It's really up to you.

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 Raikir-i-sh · Aug 24, 2020 at 12:49 PM 1
Share

lol, that's exactly what I did. I actually solved this problem then made this post so that others can later on use it if needed.

avatar image sacredgeometry Raikir-i-sh · Aug 24, 2020 at 01:03 PM 0
Share

Great $$anonymous$$ds think alike. Thanks for accepting the answer.

avatar image
0

Answer by Raikir-i-sh · Aug 24, 2020 at 12:47 PM

So after hours I made this code. I hope its helpful for others. You can use this for any other thing not just UI. I am in no way an expert coder so If you have better way of doing this , plz feel free to share.

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ScalerZeroToOne : MonoBehaviour
 {
     // Start is called before the first frame update
     public RectTransform rect;
     public Transform trans;
     public GameObject shopUi;
     public float speed = 2f;
 
     bool openShop = false;
     bool shopHold = false;
     float t = 0f;
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.I))  openShop = !openShop;
 
         ShopUIcheck();
 
     }
 
     private void ShopUIcheck()
     {
         if (!openShop)
         {
             if (t <= 0)
             {
                 shopUi.SetActive(false);
                 t = 0f;
                 return;
             }
             t -= speed * Time.deltaTime;
         }
         else if (openShop && t < 1.0f)
         {
             t += speed * Time.deltaTime;
             shopHold = true;
         }
         else if (shopHold && openShop)
         {
             return;
         }
         print(t);
         shopHold = true;
         shopUi.SetActive(true);
         float scal = Mathf.Lerp(0, 1 , t);
         if(rect ==null) { trans.localScale = new Vector3(scal, scal); }
         rect.localScale = new Vector3( scal, scal);
      
     }
  }
 


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 sacredgeometry · Aug 24, 2020 at 12:48 PM 0
Share

As you used my answer can you mark it as correct please?

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

132 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 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

Display upscale filtering? 1 Answer

Scaling of instantiated ParticleSystem 0 Answers

trees in terrain sizing 3 Answers

Child object changes scale 1 Answer

how to change pitch of sound without changing speed? wav file 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