I don’t know your skill level, so I’ll try to include some explanations instead of just some code.
To use functions like GetComponent in C# you need to understand that C# does not do dynamic typing. A line of code such as
mouseL = gameobj.GetComponent(MouseLook)
has no information at all about the types involved, so the compiler will not have a clue what to do! The compiler might think something like: [quote=The Compiler]
GetComponent() returns a Component… And you want to stick that in MouseLook variable?! Are you crazy?
[/quote]
Let’s modify the example so the compiler can read it:
Here’s what happened: First, we told C# that ‘mouseL’ is an object of the MouseLook class. Next, GetComponent() in C# doesn’t take an object or class as an argument, but only their types. This is why you wrap the name of the class in typeof(), which retrieves the type for you. Finally, GetComponent() returns a reference of the type Component. But a Component object is not a MouseLook object! The reverse is true though, so you can typecast the Component to MouseLook. (If that doesn’t make sense you should read up on object oriented programming, and specifically inheritance.