How to use classes proper way?

Hi Im currently stuck at classes I watched numerous tutorials about classes I got the but I dont seem to get their usage.
I have object spawning obstacles, spawners code is

function Update ()
{
	time -= Time.deltaTime; 				
	if(time <= 0)
	{						
		var cube : GameObject = spawnPoints[Random.Range(1,6)]; 
		var currentObstacle : GameObject = GameObject.Instantiate(obj2, cube.transform.position - Vector3(0,0.5,0), cube.transform.rotation);
		currentObstacle.AddComponent("scriptObstacleCube");
		currentObstacle.Spawn(1);                                                                                  //I wanted to give this object basic parameters by class but it doesnt work.
		currentObstacle.GetComponent(scriptObstacleCube).speed = currentSpeed;
		time = frequency;
	}
}

and spawned object has basic class:

public class Spawn {
	public var number : int;
	function Spawn(number : int)
	{
		this.number = number;
	}
}
public var test : Spawn = new Spawn(5);

Ok, now the problem is I want spawner to create obstacle and give it basic parameters using class. However I see I could just use regular function instead of class. I need explaination how to use class to instantiate objects etc, tutorials I saw are not about usage in object operations, and where should I declare class? (in spawner or in the spawned object)
If something is unclear Ill clarify.

Classes are really useful if you want to separate code that you plan on using again and again so that you don’t have to keep rewriting it, it makes your code easier to read and more efficient!

Watch the Learn tutorial on classes and try to replicate what they have done, writing it out yourself helps you to see what everything is doing and how they interact with each other:

http://unity3d.com/learn/tutorials/modules/beginner/scripting/classes

What you attach your script to kind of depends on what your code does and what you want to achieve. If you want your class to be available all the time then it might be best to attach it to an empty gameObject in the scene. If you want to reference a class from another script then you can use the GetComponent() function in the Awake() method to gain access to its functions.

Unfortunately I use C# so I find it a little hard to tell if your script has any obvious problems but if you have any questions about class and method usage then I can offer advice :).