Controlling Speed
// Define public global variables
// These will appear in the Inspector tab
public float speed = 3.5F;
public Vector3 destination;
// Only runs once
void Start()
{
// Initialize the destination location
destination = new Vector3(20.0F, 0, 0);
}
// Runs each frame
void Update()
{
// Example of updating position
transform.position += new Vector3(1.0F, 0, 0) * speed * Time.deltaTime;
// Example of using Translate()
transform.Translate(new Vector3(1.0F, 0, 0) * speed * Time.deltaTime);
// Example of using Vector3.Lerp()
transform.position = Vector3.Lerp(transform.position, destination, speed * Time.deltaTime);
}Last updated