How to enbed gui in code?

Hi there, when I try to do gui stuff inside my normal code I just get errors. What I need is just printing out datas on screen. So how to place gui text on screen?

function Update(){
	
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hit : RaycastHit;
	

		if (Physics.Raycast (ray, hit, 10)) {
				  
		Debug.DrawLine (transform.position, hit.point, Color.yellow);    
		transform.renderer.material.color = Color.magenta;
		}
														
      		else transform.renderer.material.color = Color.grey;
                              
            if (hit.transform.tag == "platedockingback"){
					transform.renderer.material.color = Color.blue;
					}
					
			if (hit.transform.tag == "platedockingfront"){
					transform.renderer.material.color = Color.green;
					}
					
			if (hit.transform.tag == "platedockingleft"){
					transform.renderer.material.color = Color.yellow;
					}
					
			if (hit.transform.tag == "platedockingright"){
					transform.renderer.material.color = Color.black;
					}
											
}

You can only call GUI code from the OnGUI function (I think GUI Texture might be an exception but don’t quote me). If you want to do something on GUI, have a conditional variable change elsewhere in your code, that then allows your datas to be visible in onGUI. If that makes sense.

All your GUI drawing code needs to be in the OnGUI function not Update.
Then it is just a matter of:

GUILayout.Label( “HELLO” );

etc