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 Nixmortem · Nov 11, 2015 at 01:22 PM · javascriptsizescaledown

Changing the size of a ball, problems with transform.localScale

I'm trying to make it so the player object, a ball, decreases in size as a timer goes down. It's supposed to be like a snowball melting. I've made a variable to represent the ball's size so it can change as the timer changes. I've tried using transform.localScale a few different ways but the ball is always increasing in size rapidly instead of decreasing slowly. I've been trying to avoid posting it on here because I'm a newbie developer and I wanted to try and figure it out on my own. But I'm stuck on this. Any help would be greatly appreciated.

 #pragma strict
 
 var maxFallDistance : int = -10;
 var ballSize:int;
 var timer : float = 10.0;
 
 function Update () {
 
     if (transform.position.y <= maxFallDistance){
         Application.LoadLevel ("Tutorial");
     }
     
     ballSize = timer; 
     Debug.Log (ballSize);
     
     timer -= Time.deltaTime;
     if(timer <= 0){
         timer = 0;
     }
     
     transform.localScale += new Vector3(ballSize,ballSize,ballSize);
 }
 
 function OnGUI(){
 
     GUI.Box(new Rect(10,10,50,20), "" + timer.ToString("0"));
 }
 

Also please don't refer me to http://docs.unity3d.com/ScriptReference/Transform-localScale.html. I tried it and tweaked it a bunch of ways but it kept making it bigger.

Thanks guys -Nix

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

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

Answer by OncaLupe · Nov 11, 2015 at 04:22 PM

You're using += to change the scale, this adds to what is already there. If you start with scale of <1,1,1> and use that with ballSize 0.9, you end up with <1.9, 1.9, 1.9>. You want to use = to assign a new value instead.

transform.localScale = new Vector3(ballSize,ballSize,ballSize);
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 Nixmortem · Nov 11, 2015 at 05:17 PM 0
Share

Thank you. That worked. I kept trying to use -= ins$$anonymous$$d of +=. I didn't think to just leave it as =. It's working now. Not the smoothest transition between size intervals but I'll work on that later. Thanks for your help.

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

Hosting both WebPlayer and WebGL builds on the same page (Unity3d 5.3.4f1). 0 Answers

Trying to use coroutines in order to use Mathf.Lerp, Lerp instantly jumps values 0 Answers

Can I use an array to determine an enclosed area and remove objects inside? 0 Answers

Set variables in an array dependent on which scene the player is in. 1 Answer

Reloads correctly first time, but can't reload till count hits 0 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