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 Dunne · Nov 09, 2014 at 04:09 PM · c#timelerpmovewait

c# wait script

Hi,

I am looking to make an object lerp left and right across the screen. i have the object lerping from one point to another but i need it to repeat from moving from right to left and back to right and so on. What is the best way to do this and how can you make it wait 1sec before it moves. if you need anymore info let me know. thanks for the help.

Comment
Add comment · Show 1
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 Dunne · Nov 09, 2014 at 03:24 PM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class move : $$anonymous$$onoBehaviour {
 
     public float smooth;
     
     private Vector3 newPosition;
 
     // Use this for initialization
     void Start () {
         newPosition = transform.position;
     }
     
     // Update is called once per frame
     void Update () {
     
 
         Vector3 positionA = new Vector3 (3, 2, 0);
         Vector3 positionB = new Vector3 (2, 2, 0);
 
         transform.position = Vector3.Lerp(transform.position, newPosition, smooth * Time.deltaTime);
     }
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by bubzy · Nov 09, 2014 at 04:50 PM

timers have been covered so many times. a simple search should yield good results.

but heres a little script just for you :D

 using UnityEngine;
 using System.Collections;
 
 public class moveWait : MonoBehaviour {
 
     float moveDelay = 1f;
     float smooth = 0.1f;
     float currentDelay;
     
     bool canMove = true;
     bool moveToA = true;
     
     Vector3 positionA = new Vector3(3,2,0);
     Vector3 positionB = new Vector3(2,2,0);
     
     void Start()
     {
         currentDelay = Time.time + moveDelay;
 
 
     }
     
     
     void Update()
     {
         if(canMove)
         {
         if(transform.position != positionA && moveToA)
         {
         moveToPosition(positionA); //start moving;
         }
 
         if(transform.position == positionA && moveToA)
         {
             moveToA = false;
             canMove = false;
             currentDelay = Time.time + moveDelay;
         }
 
         if(transform.position != positionB && !moveToA)
         {
             moveToPosition(positionB); //start moving;
         }
         
         if(transform.position == positionB && !moveToA)
         {
             moveToA = true;
             canMove = false;
             currentDelay = Time.time + moveDelay;
         }
         }
 
         if(!canMove && Time.time > currentDelay)
         {
             canMove = true;
             currentDelay = Time.time + moveDelay;
         }
         
 
             
     }
 
 
     void moveToPosition(Vector3 target)
     {
         transform.position = Vector3.Lerp(transform.position, target,  Time.deltaTime);
     }
 
 }
 
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 Dunne · Nov 09, 2014 at 05:37 PM 0
Share

bubzy thanks for the help. it is working but it is a small get slow. it moves fast at first and then it slows down and slowley moves to 3,2,0 how can you make it to get to its position in one smooth swipe and not slow down just before it gets to its 1st and 2nd position. thanks again!!

avatar image
1

Answer by Vederant · Nov 09, 2014 at 04:56 PM

 void Update () {
     StartCoroutine(wait());
 }
 public IEnumerator move () {
          yield return new WaitForSeconds (1.0f); //this stops the coroutine for 1 second.
          Vector3 positionA = new Vector3 (3, 2, 0);
          Vector3 positionB = new Vector3 (2, 2, 0);
  
          transform.position = Vector3.Lerp(transform.position, newPosition, smooth * Time.deltaTime);
 
 } 

I hope this helped.

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 bubzy · Nov 09, 2014 at 05:11 PM 0
Share

this isnt switching from positionA to positionB and you aren't calling the move() function.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Time.deltaTime making color lerp appear fast, but won't reach 1 1 Answer

What is wrong with this script ? if duration is 10 why the transform is moving in 11 seconds and not 10 ? 1 Answer

Multiple Cars not working 1 Answer

how to use time on lerp 2 Answers

Distribute terrain in zones 3 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