• 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 yaezah · Sep 18, 2017 at 09:50 PM · transformscalelocalscaletime.time

How to make an object's localscale values grow and shrink within a few seconds?

I'm trying to make this 2D sprite pulsate from small to big within 2 seconds. I've went through a few Unity questions and the closest one that works is this:

     public float amplitude;
     public Vector3 scale;


 void Start()
 {
     
     AudioControl.Instance.spin();
     Destroy(gameObject, 2.5f);
 }


 // Update is called once per frame
 void Update () {
     
     for (int i = 0; i < 3; ++i)
     {
         scale[i] = amplitude * Mathf.Sin(Time.time) + 1;
     }
     transform.localScale = scale;

    
 }

}

The problem with this script is that is it going by Time.time and every time the object is instantiated it's not starting off from localScale 1 , but continuing from the same position as the others .

Comment
Add comment · Show 2
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 Cherno · Sep 18, 2017 at 11:13 PM 0
Share

Use Time.deltaTime ins$$anonymous$$d of Time.time.

avatar image hexagonius · Sep 19, 2017 at 07:53 AM 0
Share

How about saving the current Time.time when starting and subtracting it? This way no matter what, the algorithm starts at time 0.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

88 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

Related Questions

Warning: "Setting scale failed, ignoring request." ? 1 Answer

How is localScale adjusted when re-parenting transforms? 2 Answers

Rescaling goes wrong? 0 Answers

Attempting to Calculate and Change Scale of Platforms Sets Scale to 0 1 Answer

LocalScale and uv 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges