Skip to content

Instantly share code, notes, and snippets.

@asus4
Created January 21, 2015 10:43
Show Gist options
  • Save asus4/e220f823693767a5f12a to your computer and use it in GitHub Desktop.
Save asus4/e220f823693767a5f12a to your computer and use it in GitHub Desktop.
Enable to edit 3D Text mesh in Unity3D
using UnityEngine;
using System.Collections;
namespace Sample
{
[RequireComponent(typeof(Collider))]
[RequireComponent(typeof(TextMesh))]
public class Editable3DText : MonoBehaviour {
TextMesh label;
TouchScreenKeyboard keyboard;
void Start()
{
label = GetComponent<TextMesh>();
}
void Update()
{
if(isEditing) {
if(!isMobileRuntime) {
foreach (char c in Input.inputString) {
if (c == "\b"[0]) {
if (keyboard.text.Length != 0) {
keyboard.text = keyboard.text.Substring(0, keyboard.text.Length - 1);
}
}
else if (c == "\n"[0] || c == "\r"[0]){
isEditing = false;
return;
}
else {
keyboard.text += c;
}
}
}
label.text = keyboard.text;
}
}
void OnMouseUpAsButton()
{
isEditing = !isEditing;
}
bool isEditing {
get {
return keyboard != null;
}
set {
if( value ) {
keyboard = TouchScreenKeyboard.Open(label.text);
}
else {
keyboard.active = false;
keyboard = null;
}
}
}
bool isMobileRuntime {
get {
return (Application.platform == RuntimePlatform.Android) || (Application.platform == RuntimePlatform.IPhonePlayer);
}
}
}
}
@QFord
Copy link

QFord commented Aug 12, 2016

I found it's not working on PC....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment