I’m following along with the Gamer to Game Developer series and with and he uses Input.eatKeyPressOnTextFeildFocus. However I get Unity.Input does not contain a definition for eatKeyPressOnTextFeildFocus. Im using unity 3.5.5f3, has this been removed? Here is the code.
using UnityEngine;
using System.Collections;
/// <summary>
/// This script is attached to the playerGui game Object.
///
/// This script accesses the playerSpawnScript to check if the player has joined.
/// This script is accessed by the playerNameScript.
/// This script is accessed by the cursorControl script.
/// </summary>
public class commWindowScript : MonoBehaviour {
//--------------------Variables Start--------------------
public string playerName;
private string messageToSend;
private string communication;
private bool showTextBox = false;
private bool sendMessage = false;
public bool unlockCursor = false;
// These are used to define the communication window.
private Rect windowRect;
private int windowLeft = 10;
private int windowTop;
private int windowWidth = 300;
private int windowHeight = 140;
private int padding = 20;
private int textFeildHeight = 30;
private Vector2 scrollPosition;
private GUIStyle myStyle = new GUIStyle();
// Quick references to the mPlayerObject and playerSpawnScript
private GameObject mpManager;
private playerSpawnScript sScript;
//---------------------Variables End---------------------
void Awake ()
{
Input.eatKeyPressOnTextFeildFocus = false;
messageToSend = "";
myStyle.normal.textColor = Color.white;
myStyle.wordWrap = true;
}
// Use this for initialization
void Start ()
{
mpManager = GameObject.Find("_mPlayerManager");
sScript = mpManager.GetComponent<playerSpawnScript>();
}
// Update is called once per frame
void Update ()
{
if (Network.peerType != NetworkPeerType.Disconnected)
{
// If the player presses the "T" key then set showTextbox to true
if ((Input.GetButtonDown("Communications"))&&(showTextBox == false))
{
showTextBox = true;
}
// If the player presses return and the text feild is visible then
if ((Input.GetButtonDown("SendMessage"))&&(showTextBox == true))
{
sendMessage = true;
}
}
}
void OnGUI ()
{
if (Network.peerType != NetworkPeerType.Disconnected)
{
windowTop = Screen.height - windowHeight - textFeildHeight;
windowRect = new Rect(windowLeft, windowTop, windowWidth, windowHeight);
// Dont display the the communication log until the player has joined the game
// or it is the server.
if ((sScript.spawned == true)||(Network.isServer == true))
{
windowRect = GUI.Window(5, windowRect, CommLogWindow, "Communications Log");
GUILayout.BeginArea(new Rect(windowLeft, windowTop + windowHeight, windowWidth, windowHeight));
if (showTextBox == true)
{
unlockCursor = true;
Screen.lockCursor = false;
// Give the text feild a name so that it can be found with GUI.FocusControl meathod.
GUI.SetNextControlName("commLogTextFeild");
messageToSend = GUILayout.TextField(messageToSend, GUILayout.Width(windowWidth));
// Give focus to the text feild so the user can start typing.
GUI.FocusControl("commLogTextFeild");
if (sendMessage == true)
{
// Only send a message if the textfeild isnt empty.
if (messageToSend != "")
{
if (Network.isClient == true)
{
networkView.RPC("SendMessage", RPCMode.All, messageToSend, playerName);
}
if (Network.isServer == true)
{
networkView.RPC("SendMessage", RPCMode.All, messageToSend, "SERVER");
}
}
// Set sendMessage to false so it does not continue to send after retrun is pressed.
sendMessage = false;
// Set showTextBox to false to the text feild is hidden.
showTextBox = false;
// Unlock the cursor.
unlockCursor = false;
// Reset the message to send.
messageToSend = "";
}
}
GUILayout.EndArea();
}
}
}
void CommLogWindow (int windowID)
{
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(windowWidth - padding),
GUILayout.Height(windowHeight - padding - 5));
GUILayout.Label(communication, myStyle);
GUILayout.EndScrollView();
}
[RPC]
void SendMessage (string message, string name)
{
// This string is displayed by the label in the CommLogWindow.
communication = name + " : " + message + "
" + "
" + communication;
}
}