- Home /
Question by
NinjaRubberBand · Feb 18, 2014 at 03:05 PM ·
positionobjectclick
Make object go to point a to b on click
I want my cube to move to a other position when i click the mouse button. I know how to script, but i just cant figure out how to do it like this. How do i achieve this?
Comment
Answer by deltamish · Feb 18, 2014 at 03:10 PM
Thats quite Simple
Here is an example
public GameObject Object;
public float speed;
public Vector3 DestinationPoint;
bool cango = false;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
cango = true;
}
if((transform.position - DestinationPoint).sqrMagnitude < 2f)
{
cango = false;
}else{
//Assuming your Starting point is the object's position
if(cango)
{
transform.position = Vector3.Lerp(transform.position,DestinationPoint,Time.deltaTime * speed);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613133925im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Click Position 1 Answer
Why Does My Object Change Position During Update? 0 Answers
GameObject.find and positioning 1 Answer
C#: Changing current position of an object in y. 1 Answer
Object position flickering 1 Answer