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
3
Question by mgc90403 · Jan 05, 2014 at 07:12 AM · gameobjectinstantiateage

Time since object was instantiated?

I want to scale an object based on how old it is. I'm sure there's a simple way to do this, but I don't see it...?? Thanks for any assistance :)

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

Answer by ncallaway · Jan 05, 2014 at 07:23 AM

You can capture the current gametime in the object's Start(), and then compare it against the current gametime in Update():

 private float initializationTime;
 
 void Start () {
     initializationTime = Time.timeSinceLevelLoad;
 }

 void Update () {
     float timeSinceInitialization = Time.timeSinceLevelLoad - initializationTime;
 }

If you want realtime elapsed instead of gametime replace Time.timeSinceLevelLoad Time.realtimeSinceStartup.

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 mgc90403 · Jan 05, 2014 at 07:26 AM 0
Share

Thank you. :) (Still new to this.)

avatar image ncallaway mgc90403 · Jan 05, 2014 at 07:33 AM 0
Share

Happy to help! For non-answers, you can leave a comment on the specific answer or question you want to respond to. Look below an answer and there's a "add new comment" button. This, for example, is a comment.

It's generally better to use that feature to make responses that aren't answers (rather than the answer box).

Stick with it! It gets easier over time. :)

avatar image
4

Answer by Seth-Bergman · Jan 05, 2014 at 07:28 AM

when you create your object, you can store its creation time.. create a script and add it to the object, then use:

 var startTime : float;
   
 function Awake(){
   startTime = Time.time;
 }

now that you have stored the creation time, you can see how long it has been around using:

 Time.time - startTime

however, if all you want is for your object to get bigger over time, all this is overkill.. for example, to scale consistently over time, you could just say something like:

 var scaleSpeed : float = 0.1;

 function Update(){
   transform.localScale += Vector3(scaleSpeed,scaleSpeed,scaleSpeed) * Time.deltaTime;
 } 

or to scale up periodically:

 function Awake(){
   InvokeRepeating("ScaleUp",10,10);
 }

 function ScaleUp(){
   transform.localScale += Vector3(scaleSpeed,scaleSpeed,scaleSpeed);
 }

 
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

20 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

Related Questions

Spawning GameObject contained within another 1 Answer

gameObject are not referenced 2 Answers

getting .Transform from instanntiated object 2 Answers

Trash Collection For Instantiated Game Object 1 Answer

Get components of multiple instantiated objects? 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