Well, I have been doing fine writing scripts, but conversation ones always get me. The audio isn’t playing, and the GUI doesn’t show up. If anyone can tell me or show me what is wrong here it would be a lot of help. (NOTE: I can sometimes get clumsy with my scripts, so forgive me if it’s something obvious.)
//The area in which you can be able to talk to the person.
var ConversationArea : GameObject;
//The different audio clips.
var PlayerHello : AudioClip;
var CitizenHello : AudioClip;
var PlayerBeMean : AudioClip;
var CitizenBeMeanResponse : AudioClip;
var PlayerCompliment : AudioClip;
var CitizenComplimentResponse : AudioClip;
var PlayerBeNice : AudioClip;
var CitizenBeNiceResponse : AudioClip;
var PlayerRob : AudioClip;
var CitizenRobResponse : AudioClip;
var PlayerMakeSmallTalk : AudioClip;
var CitizenMakeSmallTalkResponse : AudioClip;
//The lengths of the audio clips.
var PlayerHelloLength : Number;
var PlayerBeMeanLength : Number;
var PlayerComplimentLength : Number;
var PlayerBeNiceLength : Number;
var PlayerRobLength : Number;
var PlayerMakeSmallTalkLength : Number;
var CitizenHelloLength : Number;
//The direction the person is facing while in conversation.
var targetPosition : Transform;
var damp: int = 5;
//The style of the buttons.
var btnTexture : GUISkin;
var CanTalk : boolean;
var Player : GameObject;
var rotationAngle : Number;
//On start.
function Start () {
CanTalk = false;
}
//When player enters the trigger.
function OnTriggerEnter (ConversationArea : Collider) {
if(Player.tag == "Player") {
CanTalk = true;
}
}
//When player exits the trigger.
function OnTriggerExit (ConversationArea : Collider) {
if(Player.tag == "Player") {
CanTalk = false;
}
}
function OnGUI () {
GUI.skin = btnTexture;
}
if(CanTalk) {
//If N is pressed, conversation will start.
if (Input.GetKeyDown("N") && CanTalk) {
//The starting "hello"s.
audio.PlayOneShot(PlayerHello);
yield WaitForSeconds(PlayerHelloLength);
audio.PlayOneShot(CitizenHello);
yield WaitForSeconds (CitizenHelloLength);
//The different buttons.
if (GUI.Button(Rect(250,150,50,30),"Be Mean")) {
audio.PlayOneShot(PlayerBeMean);
yield WaitForSeconds (PlayerBeMeanLength);
audio.PlayOneShot(CitizenBeMeanResponse);
}
if (GUI.Button(Rect(250,190,50,30),"Compliment")) {
audio.PlayOneShot(PlayerCompliment);
yield WaitForSeconds (PlayerComplimentLength);
audio.PlayOneShot(CitizenComplimentResponse);
}
if (GUI.Button(Rect(250,230,50,30),"Be Nice")) {
audio.PlayOneShot(PlayerBeNice);
yield WaitForSeconds (PlayerBeNiceLength);
audio.PlayOneShot(CitizenBeNiceResponse);
}
if (GUI.Button(Rect(250,270,50,30),"Rob")) {
audio.PlayOneShot(PlayerRob);
yield WaitForSeconds (PlayerRobLength);
audio.PlayOneShot(CitizenRobResponse);
}
if (GUI.Button(Rect(250,310,50,30),"Make Small Talk")) {
audio.PlayOneShot(PlayerMakeSmallTalk);
yield WaitForSeconds (PlayerMakeSmallTalkLength);
audio.PlayOneShot(CitizenMakeSmallTalkResponse);
}
}
}
//Rotation, not done, work on it later.
if (rotationAngle) {
Quaternion.LookRotation(targetPosition.position - transform.position);
}
The booleans work correctly, and yield WaitForSeconds has given me trouble in the past, so I’m not exactly sure what could have gone wrong. Thanks in advance! (P.S. I know that the rotation isn’t done yet, I just want to get the actual conversation done first.)