Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 nicocabal02 · Apr 15 at 11:14 PM · script.scale

Scale an object over time without Lerp

i need to scale an object from "a" scale to "b" scale. I just dont need the smooth scaling that Lerp has.

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

Answer by ogulcan_topsakal · Apr 17 at 04:43 PM

@nicocabal02 I wrote a solution that you can apply by using Coroutine for the question by taking the path too long. You can eliminate smoothing completely by playing with the variables. In the update() method, you can also solve the problem by calling the processes in the coroutine separately. I made a different suggestion below the sample script.

 private const float Tolerance = 0.01f;
 private const float UpdateInterval = 0.05f;
 
 private void Start()
 {
     StartCoroutine(ScaleAtoB(transform, Vector3.one, new Vector3(0f, 2f, 1f), .25f));
 }
 
 private IEnumerator ScaleAtoB(Transform t, Vector3 initialScale, Vector3 finalScale, float incrementalSpeed, bool setInitialScale = true)
 {
     if (setInitialScale)
     {
         t.localScale = initialScale;
     }
    
     var localScale = t.localScale;
     float xIncrement = GetIncrementOverTime(localScale.x, finalScale.x) * incrementalSpeed;
     float yIncrement = GetIncrementOverTime(localScale.y, finalScale.y) * incrementalSpeed;
     float zIncrement = GetIncrementOverTime(localScale.z, finalScale.z) * incrementalSpeed;
 
     localScale = new Vector3(localScale.x + xIncrement, localScale.y + yIncrement, localScale.z + zIncrement);
     t.localScale = localScale;
 
     yield return new WaitForSeconds(UpdateInterval);
     
     if (Mathf.Abs(localScale.x - finalScale.x) > Tolerance ||
            Mathf.Abs(localScale.y - finalScale.y) > Tolerance ||
            Mathf.Abs(localScale.z - finalScale.z) > Tolerance)
     {
         yield return StartCoroutine(ScaleAtoB(t, initialScale, finalScale, incrementalSpeed, false));
     }
 }
 
 private static float GetIncrementOverTime(float localAxis, float finalAxis)
 {
     if (localAxis > finalAxis) return -1 * Time.deltaTime;
     return Time.deltaTime;
 }

I suggest you DOTween since there is no indication about using asset in the problem. You can find exactly what you need by looking through its documentation. To give two very simple examples:

 //DOTween - https://assetstore.unity.com/packages/tools/animation/dotween-hotween-v2-27676
  
 //DOTween Solution - 1
 public void ScaleAtoB(Transform t, Vector3 initialScale, Vector3 finalScale, float time)
 {
     t.localScale = initialScale;
     t.DOScale(finalScale, time);
 }
 
 //DOTween Solution - 2
 public void ScaleAtoB(Transform t, Vector3 initialScale, Vector3 finalScale, float time)
 {
     t.localScale = initialScale;
     DOTween.To(() => t.localScale, x => t.localScale = x, finalScale, time);
 }

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

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

How to scale a object with distance from the center of the canvas? 1 Answer

How to change the scale of a sprite from the c# script? 1 Answer

Cannot reduce localScale to 0 1 Answer

How to Scaling object with new UI slider ? 1 Answer

How make space scaled system (3d skybox ) 0 Answers


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