- Home /
Code error Javascript GUI text
I'm trying to make a code where when you get close enough and press the E key GUI text appears and doesn't allow you to move. I got 4 errors that I can't really figure out how to fix the. The video I watched was https://cgcookie.com/unity/2012/02/20/unity-script-npc-talk-system/ and link text. I combined the two because the cgcookie one had text appear as soon as you walked near the person rather than having the player press a button to activate text. I would appreciate if someone could either help me fix this code and set me on the right track. Code: #pragma strict
var Distance : float; var talkTextGUI=GUIText; var talkLines:String[]; var MaxDistance : float = 1.5;
private var talking:boolean; private var playerScript:PlayerScript; private var currentLine:int;
function Update () { var hit : RaycastHit; if (Physics.Raycast (Transform.position, transform.TransformDirection(Vector3.forward), hit))
{ Distance = hit.distance; if (Distance < MaxDistance) talking = true; currentLine = 0; talkTextGUI.text = talkLines[currentLine]; playerScript.enabled = false;
} function Update (); if(talking) if(Input.GetButtonDown("E")) if(currentLine < talkLines.Length - 1) currentLine++; talkTextGUI.text = talkLines[currentLine];
{ } else{ currentLine = 0; talkTextGUI.text = ""; talking = false; playerScript.enabled = true;
{
}
function Update () {; } }
The errors are: (28,10) expecting (, found 'Update'.
(37,1) expecting }, found 'else'.
(50,10) expecting (, found 'Update'.
(50,19) ';' expected. Insert a semicolon at the end.
Please select all of your code and press the 101010 button to format it.
Your answer