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 /
This question was closed Mar 04, 2018 at 11:49 PM by prim200 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by prim200 · Jan 23, 2018 at 03:08 PM · transformvector3scalecubegetkey

How can I scale an object with keyinput and return old scale when I do not press like Mario crunch

The thing is I only want him to scale this 1 time when I key is pressed and only y should change.

 void Update () {

     if (Input.GetKey("down"))
 
     {
         transform.localScale = new Vector3(0, 0.25f, 0)* 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

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by andracer108 · Jan 24, 2018 at 06:14 AM

Ok, so the answer is simple. You are only providing an "if" statement for what would happen when the user presses "down". But what would happen if the user releases it? How you wrote the code, nothing would happen. And this is because, as said before, you are only supplying an "if" statement to when the user is holding the button down.

To fix this, all you have to do is add an "else" statement after you close the "if". After you opened up the "else" statement within it, write the code to make the character have normal size again. Speaking of size, I think the size you're applying is wrong as well. You're making the x and z sizes 0 which would make your character disappear, which I'm assuming you don't want. Anyways, the code would look something like this:

 void Update () {
      if (Input.GetKey("down"))
      {
          transform.localScale = new Vector3(1f, 0.25f, 1f) * Time.deltaTime;
      }
      else
      {
          transform.localScale = new Vector3(1f, 1f, 1f) * Time.deltaTime;
      }
 }


Hope this helps! And if it did, kindly mark as answered. :)

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 prim200 · Mar 04, 2018 at 11:46 PM 0
Share

Thanks alot but I have changed my project long time ago just saw that you answered :) I appreciate your help

avatar image andracer108 prim200 · Mar 06, 2018 at 03:35 PM 0
Share

It's no problem at all! I'm glad I helped. :) Good luck with your new project!

Follow this Question

Answers Answers and Comments

108 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

Related Questions

scale to vector3 point 1 Answer

I'm trying to make a zoom by changing the scale of the object and need constraints 1 Answer

How to smooth transform scaling with 2d sprite 1 Answer

TextMeshPro Height 0 Answers

How can I turn my cube object to the direction it is traveling? 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