Changing MouseOrbit to W,A,S,D (This is a C# version)

Hi friends,

I’m using a translated version of MouseOrbit.js (I believe) in C# to rotate around my character. How do I change the orbit from using my mouse X, Y to using a key? Most likely W,A,S,D. Also I can’t tell, I have two scripts running, does this script control my zoom? This script overrides the other, so we will start here.

using UnityEngine;
using System.Collections;

public class Rotate : MonoBehaviour 
{
	public Transform target;
	public float distance = 10.0f;
	
	public float xSpeed = 250.0f;
	public float ySpeed = 120.0f;
	
	public float yMinLimit = -20;
	public float yMaxLimit = 80;
	
	private float x = 0.0f;
	private float y = 0.0f;
	
	void Start () 
	{
		var angles = transform.eulerAngles;
		x = angles.y;
		y = angles.x;
		
		// Make the rigid body not change rotation
		if (rigidbody) 
			rigidbody.freezeRotation = true;
	}
	
	void LateUpdate () 
	{
		if (target)
		{
			x += Input.GetAxis("Mouse X") * xSpeed * Time.deltaTime;
			y -= Input.GetAxis("Mouse Y") * ySpeed * Time.deltaTime;
			
			y = ClampAngle(y, yMinLimit, yMaxLimit);
			
			transform.rotation = Quaternion.Euler(y, x, 0);
			transform.position = (Quaternion.Euler(y, x, 0)) * new Vector3(0.0f, 0.0f, -distance) + target.position;
		}
	}
	
	static float ClampAngle(float angle, float min, float max) 
	{
		if (angle < -360)
		{
			angle += 360;
		}
		if (angle > 360)
		{
			angle -= 360;
		}
		return Mathf.Clamp(angle, min, max);
	}
}

You simply need to change the input axis that is used. The code below shows what the LateUpdate method should look like so you can can use WASD (or arrows) to orbit the object.

    void LateUpdate()
    {
        if (target)
        {
            x += Input.GetAxis("Horizontal") * xSpeed * Time.deltaTime;
            y -= Input.GetAxis("Vertical") * ySpeed * Time.deltaTime;

            y = ClampAngle(y, yMinLimit, yMaxLimit);

            transform.rotation = Quaternion.Euler(y, x, 0);
            transform.position = (Quaternion.Euler(y, x, 0)) * new Vector3(0.0f, 0.0f, -distance) + target.position;
        }
    }

Also your script does not do any zooming.