Scrollview scrollposition follow text

Hey! I’m trying to make my own console in Unity using the regular UnityGUI, everything seems to work like I want it to except one simple thing.

The GUILayout.Scrollview I have made will not follow the text as I print more lines to the console, it stays wherever I’ve moved it. I do not want it to follow the text always like if I just set the Vector2 to infinity, I want to be able to scroll around in the console without problems, only if I’m scrolled down to the bottom should the console follow the text.

If I’m at the top of the console and something prints further down I don’t want the console to jump down there forcing the user to scroll back up, but if the user was already looking at the bottom I want it to follow the new text.

I really hope that made sense, here is the code I have at the moment:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SimpleConsole : MonoBehaviour {
	bool isVisible = false;

	public GUISkin customSkin;

	public List<string> consoleLog = new List<string>();
	internal string consoleBuffer = "";
	private List<string> pastCommands = new List<string>();
	Vector2 scrollPosition = Vector2.zero;
	

	FunctionHandler funcHandler;

	// Use this for initialization
	void Start () 
	{
		funcHandler = gameObject.GetComponent<FunctionHandler>();
	}
	
	// Update is called once per frame
	void Update () 
	{
		if (Input.GetButtonDown("Console"))
		{
			ToggleConsole();
		}
	}

	// Toggle if the console is visible...
	void ToggleConsole ()
	{
		if (isVisible)
		{
			isVisible = false;
		}else{
			isVisible = true;
		}
	}

	void OnGUI ()
	{
		if (isVisible)
		{
			GUI.skin = customSkin;

			// Background box.
			GUI.Box(new Rect(0,0,Screen.width, Screen.height),"");

			// Input area
			Event e = Event.current;
			if (e.type == EventType.KeyDown  e.keyCode == KeyCode.Return)
			{
				AddConsoleQuery(consoleBuffer);
				consoleBuffer = "";
			}
			GUI.SetNextControlName("Input");
			consoleBuffer = GUI.TextField(new Rect(10,(Screen.height/100)*85,Screen.width - 20, 20),consoleBuffer);

			// Log box.
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(Screen.width - 20), GUILayout.Height((Screen.height/100)*80));
			foreach(string message in consoleLog)
			{
				// Print all messages in consoleLog on separate lines.
				GUILayout.Label(message);
			}
			GUILayout.EndScrollView();

			GUI.FocusControl ("Input");
		}
	}

	// This is used to add queries to the console which will call functions.
	public void AddConsoleQuery(string message)
	{
		consoleLog.Add("<< " + message);
		pastCommands.Add (message);
		HandleCommand(message);
	}

	// This is used for functions to respond to the users queries.
	public void AddConsoleAnswer(string message)
	{
		consoleLog.Add(">> " + message);
	
	}

	// This simply sends the command to the functionhandler which will make sure the function is allowed to be used and then carry it out.
	// The function will send back an AddConsoleAnswer when it's done.
	public void HandleCommand(string message)
	{
		funcHandler.CheckFunction(message);
	}
}

Did you find the answer? I’m about to tackle this right now myself.