I am trying to make a script to rotate the camera around a central point using the arrow keys. The script currently looks like this: `using UnityEngine;
using System.Collections;
public class NewCameraControl : MonoBehaviour {
protected float fDistance;
protected float fSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetKey(KeyCode.RightArrow))
{
orbitTower(false);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
orbitTower(true);
}
if (Input.GetKey(KeyCode.UpArrow))
{
moveInOrOut(false);
}
if (Input.GetKey(KeyCode.DownArrow))
{
moveInOrOut(true);
}
}
protected void orbitTower(bool bLeft)
{
float step = fSpeed * Time.deltaTime;
float fOrbitCircumfrance = 2F*fDistance*Mathf.PI;
float fDistanceDegrees = (fSpeed / fOrbitCircumfrance) * 360;
float fDistanceRadians = (fSpeed / fOrbitCircumfrance) * 2*Mathf.PI;
if (bLeft)
{
transform.RotateAround(Tower.t().transform.position, Vector3.up, -fDistanceRadians);
}
else
{
transform.RotateAround(Tower.t().transform.position, Vector3.up, fDistanceRadians);
}
}
protected void moveInOrOut(bool bOut)
{
if (bOut)
{
transform.Translate(0,0,-fSpeed, Space.Self);
}
transform.Translate(0,0,fSpeed, Space.Self);
}
}
`
Sorry that the code is in C#, I know UnityScript is more popular. The problem is that when I press the right and left arrow keys to orbit the camera (I’m not working on the in/out functionality right now), I get weird errors that I do not understand:
Does anyone know what’s wrong and how I can fix it? Thanks!