# General programming question C# Unity

**URL:** https://discussions.unity.com/t/general-programming-question-c-unity/184883
**Category:** Questions & Answers
**Created:** [March 30, 2017, 5:02am UTC](https://discussions.unity.com/t/general-programming-question-c-unity/184883 "2017-03-30T05:02:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Creepercatss](https://avatars.discourse-cdn.com/v4/letter/c/e95f7d/32.png) [@Creepercatss](https://discussions.unity.com/u/Creepercatss)
#### Post date: [March 30, 2017, 5:02am UTC](https://discussions.unity.com/t/general-programming-question-c-unity/184883/1 "2017-03-30T05:02:01Z")

</div>

Hello everyone! I had a question that i kept asking myself and could never figure a proper way to do this.

What i want to happen is something like this.

-User presses key once  
– An object moves from one spot to another using Vector3.Lerp  
Vector3.Lerp requires it to be repeated either in the update method or some other way.  
I was wondering what the most efficient way i could make this happen with just one button press  
and not have to hold down the button.

Thanks in advance to everyone! Happy developing!

---

<div class="post-metadata">

### Author: ![SohailBukhari](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sohailbukhari/32/908689_2.png) [@SohailBukhari](https://discussions.unity.com/u/SohailBukhari)
#### Post date: [March 30, 2017, 8:35am UTC](https://discussions.unity.com/t/general-programming-question-c-unity/184883/2 "2017-03-30T08:35:30Z")

</div>

@username

if you don’t want to move in update or not want to press the button to move,then there is a simple way of moving object.

1. Make a thread to move object.
2. Make Two points to move from one  
point to other.
3. Time For moving object to  
destination.

class MyClass: MonoBehaviour  
{

```
         [SerializeField]private Vector3 _pointBVector3;
     
         private void Start()
         {
             var pointAVector3 = this.transform.position;
             StartCoroutine(MoveObject(this.transform,pointAVector3,_pointBVector3,Random.Range(2f,5f)));
         }
         /// <summary>
         /// MoveObject
         /// </summary>
         /// <param name="_transform">Pass transform Which You Want To Move</param>
         /// <param name="initialPos">Start Position Of Move Object</param>
         /// <param name="endPos">PointB </param>
         /// <param name="time">Random Time Like Random.Range(2f,5f)</param>
         /// <returns></returns>
         private IEnumerator MoveObject(Transform _transform,Vector3 initialPos,Vector3 endPos,float time)
         {
             var i = 0.0f;
             float rate = 1.0f / time;
             while (i < 1.0f)
             {
                 i += Time.deltaTime * rate;
                 _transform.position = Vector3.Lerp(a: initialPos, b: endPos, t: i);
                 yield return null;
             }
         }
     }

```
