Calling a method twice in Start without overwriting
Hello, I'm a bit new to unity and am wondering how I can call this method twice.
I am trying to move an object from one point to another, and then another.. etc as many times as id like:
public class Motion : MonoBehaviour {
float t;
Vector3 startPosition;
Vector3 target;
float timeToReachTarget;
void Start()
{
startPosition = target = transform.position;
SetDestination(new Vector3(1, -2, 2), 2f);
SetDestination(new Vector3(0, 1, 1), 5f);
}
void Update()
{
t += Time.deltaTime / timeToReachTarget;
transform.position = Vector3.Lerp(startPosition, target, t);
}
public void SetDestination(Vector3 destination, float time)
{
t = 0;
startPosition = transform.position;
timeToReachTarget = time;
target = destination;
}
}
Comment
Can you please clarify what you are trying to do? For instance, the SetDestination in the Start() method will instantaneously move the object from one location to another. Is that what you want?
yup exactly, so like first go from (0,0,0) to (1,-2,2) and then from (1,-2,2) to (0,1,1)
Your answer
Follow this Question
Related Questions
Not moving,please help 1 Answer
Jumping in my script deosnt work,How make this script to jump? 0 Answers
Character Rotation 0 Answers
Continous movement issue 0 Answers
How can I state the movement speed of this script? 0 Answers