# Why Does This C# Code Do Nothing?

The following is the included MouseOrbit script tentatively converted to C#. This is the first time I've ever worked with C#, so my code may well not make any sense- if that's the case, just say so.

``````using UnityEngine;
using System.Collections;

public class ORBITALMOUSE: MonoBehaviour {
Transform target;
double distance= 10.0f;

double xSpeed= 250.0f;
double ySpeed= 120.0f;

double yMinLimit= -20;
double yMaxLimit= 80;

private double x= 0.0f;
private double y= 0.0f;

partial class MouseOrbit { }

void  Start (){
Vector3 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 * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

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

transform.rotation = rotation;
transform.position = position;
}
}
}

``````

I've attached this code to a camera object and its target is a basic sphere. Can anyone tell me why this code seems to have no effect?

This is the MouseOrbit script converted to Unity's mono (almost C#, but not quite):

``````using UnityEngine;

public class MouseOrbit : 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 (){
Vector3 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 * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

y = ClampAngle(y, yMinLimit, yMaxLimit);

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

transform.rotation = rotation;
transform.position = 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);
}
}

``````

The partial class isn't really hurting anything, but since it's empty, why is it there?

Your script is set to follow a target transform, but that transform is private and is never set, therefore your code in LateUpdate will never get inside your if statement and will never do anything.

Also, if you have the standard asset mouse orbit, it will also try to add itself as a component called Camera-Control/MouseOrbit. You should consider adding your custom mouselook under a different menu entry.

Do you have to put the functions inside that "Partial class" definition? I see empty brackets and they make me sad, but I've never encountered "partial class" before so I could be being insane.

Check to make sure your xSpeed and ySpeed aren't zero, and that your mousex/y axes are set up properly and that you've assigned a target.