Understanding the Mouselook, to make my own.

Ok here is the default mouselook we get, and I have a bit of questions to ask about it.

using UnityEngine;
using System.Collections;

[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour {

	public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
	public RotationAxes axes = RotationAxes.MouseXAndY;
	public float sensitivityX = 15F;
	public float sensitivityY = 15F;

	public float minimumX = -360F;
	public float maximumX = 360F;

	public float minimumY = -60F;
	public float maximumY = 60F;

	float rotationY = 0F;

	void Update ()
	{
		if (axes == RotationAxes.MouseXAndY)
		{
			float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
			
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
			
			transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
		}
		else if (axes == RotationAxes.MouseX)
		{
			transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
		}
		else
		{
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
			
			transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
		}
	}
	
	void Start ()
	{
		// Make the rigid body not change rotation
		if (rigidbody)
			rigidbody.freezeRotation = true;
	}
}

1.

using UnityEngine;
using System.Collections;

What is that ?

2.

[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour {

	public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
	public RotationAxes axes = RotationAxes.MouseXAndY;

What is the addcomponentmenu thing?
What exactly is a MonoBehavior?
What is a enum and how does the stuff in the { } work ?
What is he doing with public rotationAxes axes=rotationaxes.mousexandy ?

3.

public float sensitivityX = 15F;

what is with the F behind 15?

4.

	void Update ()
	{
		if (axes == RotationAxes.MouseXAndY)

What is with the void in void Update() ?
How does the if statement here work, it kinda throws me off (maybe because i dont understand the questions i posted above)?

5.

	void Start ()
	{
		// Make the rigid body not change rotation
		if (rigidbody)
			rigidbody.freezeRotation = true;
	}

again what is the void, and what rigid body is it freezing and why ?

6.

Could I get just a general run down of how the script works mainly in the If statement area since i already asked about most of the rest?

Thank you so much for taking your time to help me understand this so I can improve my abilities.

  1. a enum is a variable which only can have some values that you have wrote in its definition in the { }. I don’t use to use this features too much.

  2. the F behind 15 is to indicate that is a float. Is the same put 15.0

I can’t answer good the other questions sorry :stuck_out_tongue:

The using statments… using blah means there is a blah file somewhere that tells the compiler how to deal with code you are writing about blah… so like the using unityengine tells the compiler how to handle code about unity specific things… such as the keyword rigidbody…

Add componet…adds an option in the componet dropdown inside the unity engine.

Void is what the function returns when it finishes… void meaning nothing.

…I just got trolled didn’t I…

I seriously thought of writing an answer here… sorry if you think i am mean, but you can find most of those answers if you just take the time to search on Script Reference and User Manual. NOTE: this code is in C#.

http://unity3d.com/support/documentation/

What do you meen when you function returns ? I dont get that part of void.

Also I am a UnityScript (java) person so I am not going to learn much from this script am i …

the function is in C#, you can learn from it the algorithm or how it works, but you have to learn more coding stuff…

void function(params){} does not return, it just works with the params, or the vars it can get it’s hands on, and changes things.

exactly this in #84 Camera Controls #1 ++

the guy in the video explains c# programing with monodevelop.
if you intermediate you can start with tutorial #100.

  1. class import to access functions. Without UnityEngine you can’t use monoBehaviour or Debug so you need to import them.
  2. add component menu adds the script to the component menu at the top bar in Camera-Control/Mouse Look
    monobehaviour is the base class that mouselook is extending from means it has the same functions like monobehaviour.
  3. in c# you have to end the float with a f but only when you writing it like this: 15.0f otherwise you would get a double exception. which means 15.0000000000000000000…
  4. void Update will be called each frame. like an enterframe or a setTimeout
  5. Start will be called on start. both Update and Start are kind of events

i suggest you just watch the tutorial and go c#