Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by lindam345 · Nov 11, 2016 at 04:38 PM · timemovinggameobject

How to move an object after an amount of time?

Hello guys!

I have a problem which cannot be solved by myself, so please help me. I want to make my object move after 10 seconds but I have no idea how to do this. I searched through questions and answers but it didn't really help.

Thank you for helping me! ...unity-noob overhere !

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 TheShadyColombian · Nov 11, 2016 at 06:04 PM

First, create two variables, a float which will represent the delay you want (in this case, 10) and the other will be a timer, whose value we will increase every frame.

In the Update() function, add a line similar to this:

 yourTimerVariable += Time.deltaTime;

This will add the time, instead of just the number of frames. Read the docs page for Time.deltaTime for more info. It's a really useful variable.

Then below that, add an if statement that verifies if the timer variable is greater than the variable which stores the delay you want, and execute whatever movement code you have inside those brackets.

Let me know if you need more help.

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
0

Answer by lindam345 · Nov 13, 2016 at 01:09 PM

At first - thank you very much @xXJuanXx! I tried to implement your suggestions but it didn't work. Either I am too dumb for this or I have an error in reasoning.

Thats my progress so far, I made the objects move before I wanted them to move after 10 seconds, so i have to change it somehow.. :

 // Use this for initialization
 void Start()
 {
 }

 // Update is called once per frame
 void Update()
     {
     delay += Time.deltaTime;
     if (timer > 10)
     {
         float step = speed * Time.deltaTime;
         transform.position = Vector3.MoveTowards(transform.position, target.position, step);
     }
     }

}

One of the problems is that my program did not want to accept float 10 . Do I have to assign 10 to float delay in another way?

Thank you for helping me!

Comment
Add comment · Show 3 · 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 TheShadyColombian · Nov 13, 2016 at 08:06 PM 1
Share

Please post further questions and other things as comments ins$$anonymous$$d of answers.

The first problem is that you are increasing the value of the delay function but you are only verifying if the timer function is greater than 10. What you should be doing is increasing the value of timer, and verifying if timer is greater than delay. You should also be assigning 10 to your delay variable during declaration or in your Start() function (or in the editor, if you don't $$anonymous$$d it being a public variable)

Here's your above code with the changes I suggested

  // Use this for initialization
  void Start() {
      //Set the value of 'delay' to 10:
      delay = 10;
  }
 
  // Update is called once per frame
  void Update() {
     //Increase the value of 'timer' by deltaTime:
      timer += Time.deltaTime;
 
      //Verify if the timer is greater than delay:
      if (timer > delay) {
 
          //If so, proceed to translate the object:
          float step = speed * Time.deltaTime;
          transform.position = Vector3.$$anonymous$$oveTowards(transform.position, target.position, step);
 
      }
  }
avatar image lindam345 TheShadyColombian · Nov 14, 2016 at 06:10 PM 0
Share

It worked! Thank you very much! You were very patient with me. I hope I can ask you another question if I am not able to manage some things by myself.

Greetings!

avatar image TheShadyColombian lindam345 · Nov 15, 2016 at 02:37 AM 1
Share

You're very welcome! I'm glad I was able to help.

If you ever need more help, create your next post with a tag of my username ( @xXJuanXx ) and I'll be notified.

Also, if it helped, make sure to mark my answer as correct. ^_^

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

79 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

Related Questions

Destroying bullets after a certain amount of time 1 Answer

make enemy cars spawn faster over time! 2 Answers

How to record lap time for player and AIs? 0 Answers

Type out text in sync with audioclip 0 Answers

How do I do math in unity.(timer/60 and timer%60) 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