DEV Community

Discussion on: Simple 3D Camera Movement in Unity

Collapse
 
shigsy profile image
shigsy • Edited

Probably best not to instantiate anything in your Update loop.

private float moveSpeed = 150.0f;
private Vector3 moveVector;

void Start()
{
    moveVector = new Vector3(0, 0, 0);
}

void Update()
{
    moveVector.x = Input.GetAxisRaw("Horizontal");
    moveVector.z = Input.GetAxisRaw("Vertical");

    if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0) {
        transform.position += moveSpeed * moveVector * Time.deltaTime;
    }

} 
Collapse
 
k1pash profile image
Christopher Toman

Good point!