Help me with this JavaScript class please(Script inside)

Hey guys, so i’m trying to restructure my mess of a code and handling it via classes, but my first class does like nothing at all!

the value i’m changing does change in the editor but the console won’t print!

EDIT : New script yet again!

var knopfbreite = 75;
var knopfhoehe = 35;
class Dashboard extends MonoBehaviour
{
	public var richtung : int = 0;
	
	
	public function Run(richtung)
	{
		
		print("in funktion");
		yield WaitForSeconds(5.0);
		switch (richtung)
		{
			case 0 : print("idle");
					 break;
			
			case 1 : print("Erster Wert!");
					 break;
			
			case 2 : print("Rewind!");
			         break;
			
			case 3 : print("Play!");
			         break;
			
			case 4 : print("Stop!");
			         break;
			
			case 5 : print("Forward!");
			         break;
			
			case 6 : print("Letzter Wert!");
			         break;
			
			case 7 : Application.Quit();
	    }
	}
};






function Start()
{
print("running");
Needles.Run(4);
	
}






function OnGUI()
{
	if(GUI.Button(Rect(10,10,knopfbreite,knopfhoehe),"Start"))
	{
		Needles.richtung = 1;
	}
	
	if(GUI.Button(Rect(85,10,knopfbreite,knopfhoehe),"Rewind"))
	{
		Needles.richtung = 2;
	}
	
	if(GUI.Button(Rect(160,10,knopfbreite,knopfhoehe),"Play"))
	{
		Needles.richtung = 3;
	}
	
	if(GUI.Button(Rect(235,10,knopfbreite,knopfhoehe),"Stop"))
	{
		Needles.richtung = 4;
	}
	
	if(GUI.Button(Rect(310,10,knopfbreite,knopfhoehe),"Forward"))
	{
		Needles.richtung = 5;
	}
	
	if(GUI.Button(Rect(385,10,knopfbreite,knopfhoehe),"End"))
	{
		Needles.richtung = 6;
	}
	
	if(GUI.Button(Rect(460,10,knopfbreite,knopfhoehe),"Quit"))
	{
		Needles.richtung = 7;
	}
}	

function Update() {

	
	
}

Any help is appreciated!

thanks in advance

bio

Once you have modified your class to extend from MonoBehaviour as this

class Dashboard extends MonoBehaviour 

Your class is now ready to be applied to a game object, Unity works with gameobjects and components, so what you need to do to instantiate your object is to actually create an empty gameobject in your scene and drop your script on it.

It will be an invisible object with an instance of your component.
Now with your code, it seems you want to control your dashboard object from outside of it, so either you have one gameobject with a global script and your Dashboard instance as another game object. In that case, your global script can get a reference to your dashboard in 2 ways:

Either you expose a public variable where you’ll be able to set your dashboard instance

public var m_Dashboard:Dashboard;

Or you can get the reference from the scene manually in your Start or Awake function

function Start()
{
    GameObject.Find("TheNameOfYourDashboardObjectInTheScene").GetComponent(Dashboard);
}

From there you can access your m_Dashboard object.

Or, your Dashboard script can do it all, the OnGUI stuff and everything.

I believe a good read for you would be the GameObject part of the Unity documention which explains Unity’s philosophy about Game objects and components.

Also some references on how to access objects and components.

And really, more generally, the scripting reference talks about some common unity scripting techniques which could settle some of these unknowns for you

As an attempt to do what you wanna do with only one game object, I suggest this script, now I’m not sure what the OnGUI part does and I assume it listened to button clicks and that it’s working this way. Notice a couple things, the richtung variable now initialized to 4 directly and the update function directly running and checking the richtung variable. So you create an empty object and drop this script on it and if OnGUI works as you coded it, it should all work and print Stop! at first until you click some buttons.

class Dashboard extends MonoBehaviour
{
	static var knopfbreite = 75;
	static var knopfhoehe = 35;
  
  private var richtung : int = 4;

    function Update()
    {

        print("in funktion");
        yield WaitForSeconds(5.0);
        switch (richtung)
        {
            case 0 : print("idle");
                     break;

            case 1 : print("Erster Wert!");
                     break;

            case 2 : print("Rewind!");
                     break;

            case 3 : print("Play!");
                     break;

            case 4 : print("Stop!");
                     break;

            case 5 : print("Forward!");
                     break;

            case 6 : print("Letzter Wert!");
                     break;

            case 7 : Application.Quit();
        }
    }
    
    function OnGUI()
		{
	    if(GUI.Button(Rect(10,10,knopfbreite,knopfhoehe),"Start"))
	    {
	        richtung = 1;
	    }
	
	    if(GUI.Button(Rect(85,10,knopfbreite,knopfhoehe),"Rewind"))
	    {
	        richtung = 2;
	    }
	
	    if(GUI.Button(Rect(160,10,knopfbreite,knopfhoehe),"Play"))
	    {
	        richtung = 3;
	    }
	
	    if(GUI.Button(Rect(235,10,knopfbreite,knopfhoehe),"Stop"))
	    {
	        richtung = 4;
	    }
	
	    if(GUI.Button(Rect(310,10,knopfbreite,knopfhoehe),"Forward"))
	    {
	        richtung = 5;
	    }
	
	    if(GUI.Button(Rect(385,10,knopfbreite,knopfhoehe),"End"))
	    {
	        richtung = 6;
	    }
	
	    if(GUI.Button(Rect(460,10,knopfbreite,knopfhoehe),"Quit"))
	    {
	        richtung = 7;
	    }
		}  
}

tried change Start into Update?