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 Spade0 · Nov 10, 2013 at 07:04 PM ·

Scaling up and down with Time?

Hi, I seem to be having an issue scaling a simple box using Time.deltaTime. The effect I'm going for is a box that spins and gets a bit bigger and then returns to its original size smoothly. But for some reason can not not get the code to loop from big to small, it simply just keeps scaling up. Iv'e been working on it for hours and it's driving me crazy. Any help would be greatly appreciated!!

Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class constantRotation : MonoBehaviour {
     
     public float rotaionspeed = 0;
     public float flux = 2.0f;
     private int flexout = 0;
     private int flexin = 21;
     
     
     
     
     public void Start ()  {
     
         
         
     }
     
     void Update () {
     
         
         transform.eulerAngles += new Vector3(0, rotaionspeed,0); //Constant Rotation
         
         if (flexout <= 20) {
             
             transform.localScale += new Vector3 (flux * Time.deltaTime,flux * Time.deltaTime,flux * Time.deltaTime);
             flexout ++;
             
         }
         
         if (flexout >= 20) {
             
             flexout = 21;
             flexin = 0;
             
         }
         
         if (flexin <= 20){
             
             transform.localScale += new Vector3 (-flux * Time.deltaTime,-flux * Time.deltaTime,-flux * Time.deltaTime);
             flexin ++;
         }
         if (flexin >= 20) {
             
             flexin = 21;
             flexout =0;
         }
     
     }
 }

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

Answer by Triqy · Nov 10, 2013 at 07:57 PM

 using UnityEngine;
 using System.Collections;
 
 public class example : MonoBehaviour {
     void Update() {
         transform.localScale = new Vector3(Mathf.PingPong(Time.time, 3), transform.localScale.y, transform.localScale.z);
     }
 }
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 Triqy · Nov 10, 2013 at 08:50 PM 0
Share

Glad i Could help! :)

avatar image Spade0 · Nov 10, 2013 at 10:50 PM 0
Share

Wow that's incredible! Thank you for your help bchilds88. I have yet to use $$anonymous$$athf, PingPong, or Time.time. It's amazing how much code I was trying to use and you simplified it down to two lines =)I would like to find out what those specifically do. Thanks again!

avatar image
2

Answer by Musabbir · Sep 24, 2019 at 04:58 PM

  using UnityEngine;
  using System.Collections;    
 
 public class ScaleUpDown: MonoBehaviour {
 
     float scalingTime, scalingSpeed = 0.3f, targetScale = 0.3f;
     float length = 0.3f;
 
     void Update ()
     {
         scalingTime = Time.time * scalingSpeed;  
         transform.localScale = new Vector3 (
             Mathf.PingPong (scalingTime, length) + targetScale, 
             Mathf.PingPong (scalingTime, length) + targetScale, 0
         );
     }
 }
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

19 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

Related Questions

How to setup a 2D Beat em up? 1 Answer

Screen Resolution Scaling No Solution? 1 Answer

Trouble getting XInput set up 0 Answers

Instantiated object has the scale of the old object that was distroied 0 Answers

Setting up an array of tags. 2 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