Guide:Unity 3D GUI: Difference between revisions

From Game Making Tools Wiki
(Created page with "==TypeWriterEffect.cs== Here's a kinda clunky little typewriter effect I found somewhere. Still trying to fidn where so I can give credit :( I've modified it ''slightly''. <p...")
 
(Added cursor stuff (might be outa date?))
 
Line 1: Line 1:
==TypeWriterEffect.cs==
==The Cursor==
===HideCursor.js===
<pre>
function Start() {
Screen.showCursor = false;
}
</pre>
This little script will prevent the mouse cursor from being shown. Note that when previewing the game in Unity the cursor will still appear.
 
If you wish to control when it it shown or not, for example when a menu appears, simple set <code>Screen.showCursor</code> to <code>true</code> when your menu is called.
 
You can also lock the cursor in place using <code>Screen.lockCursor</code>.
 
==Effects==
===TypeWriterEffect.cs===
Here's a kinda clunky little typewriter effect I found somewhere.
Here's a kinda clunky little typewriter effect I found somewhere.
Still trying to fidn where so I can give credit :(
Still trying to fidn where so I can give credit :(

Latest revision as of 15:26, 16 October 2016

The Cursor

HideCursor.js

function Start() {
	Screen.showCursor = false;
}

This little script will prevent the mouse cursor from being shown. Note that when previewing the game in Unity the cursor will still appear.

If you wish to control when it it shown or not, for example when a menu appears, simple set Screen.showCursor to true when your menu is called.

You can also lock the cursor in place using Screen.lockCursor.

Effects

TypeWriterEffect.cs

Here's a kinda clunky little typewriter effect I found somewhere. Still trying to fidn where so I can give credit :( I've modified it slightly.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TypeWriterEffect : MonoBehaviour {

	public float delay = 0.1f;
	[TextArea(4,10)]
	public string fullText;
	private string currentText = "";

	void Start () {
		StartCoroutine(ShowText());
	}

	IEnumerator ShowText(){
		for(int i = 0; i < fullText.Length; i++){
			currentText = fullText.Substring(0,i);
			this.GetComponent<Text>().text = currentText;
			yield return new WaitForSeconds(delay);
		}
	}
}