- Home /
Problem with Conversation C# script / Talking
Hey everyone, ok so I will explain my problem first. I got that script for conversation with NPC, it works perfectly when I come closer to the NPC with this script the box pops up and there are option to choose from what to say. However when I try to click something I keep moving the camera with mouse, and when I try to click I keep shooting but can't click any option from conversation. When I click escape and cursor from desktop appears It also doesn't work but when I click somewhere else on desktop or website and back to Unity I can click option 1/2 but than whole problem appears again. What I need and because I am crap at programming I need a IF statement that when player start conversation the controller freeze I think that would do the job I THINK, but I don't know what and where to put it this. Hopefully I explain my problem well, here is the Script I wrote;
//---------------------------------------------- // ----- Declare Variables
// Game Objects
private GameObject go_Player;
//Dialogue Variables
public string st_NPC_name = "Interfering Old Lady";
public string st_NPC_inital_text = "By the light, God has send it you!";
public string st_Player_response_1 = "Sorry Madam, Are you alirhgt there?";
public string st_Player_response_2 = "Are you another crazy b**ch ?";
public string st_NPC_outcome1 = "Please, Save my daughter from danger. Shes at the end of the maze, please. Here is the key to open doors to it";
public string st_NPC_outcome2 = "No? Why you laughting at me? Do I look silly for you motherfu**er ?";
public string st_NPC_return_text = "Go, Go and save her";
private string st_NPC_outcome;
private bool bl_dialogue_on;
private bool bl_Player_responded;
private bool bl_conversation_complete;
//---------------------------------------------------------------
// Use this for initialization
void Start () {
// Find Game Objects
go_Player = GameObject.Find ("Player");
}//---
//-------------------------------------------------------
// Update is called once per frame
void Update () {
// Turn the GUI box when the PC is close
if (Vector3.Distance( transform.position , go_Player.transform.position) < 3 ){
bl_dialogue_on = true;
}
else{
bl_dialogue_on = false;
}
}//---
///-------------------------------------------------------------
// ----- Interface Control GUI Display
void OnGUI(){
if (bl_dialogue_on){
// Draw Outline Box
GUI.Box(new Rect ((Screen.width/2)-200, (Screen.height/2)-150, 400, 250), st_NPC_name);
if (!bl_conversation_complete){
if (!bl_Player_responded){
// NPC Inital text
GUI.Label(new Rect ( (Screen.width/2)-160, (Screen.height/2)-120, 350, 50), st_NPC_inital_text);
// PC option 1
if ( GUI.Button(new Rect ( (Screen.width/2)-180, (Screen.height/2)-60, 350, 60), st_Player_response_1) ) {
// Set NPC response 1 and flag we have spoken
st_NPC_outcome = st_NPC_outcome1;
bl_Player_responded = true;
}
// PC option 2
if ( GUI.Button(new Rect ( (Screen.width/2)-180, (Screen.height/2)+10, 350, 60), st_Player_response_2) ) {
// Set NPC response 1 and flag we have spoken
st_NPC_outcome = st_NPC_outcome2;
bl_Player_responded = true;
}
}
else {
// bl PC responded is now true
// Display the NPC response to the PC's Choice
GUI.Label(new Rect ( (Screen.width/2)-180, (Screen.height/2)-130, 350, 50), st_NPC_outcome);
// PC Goodbye - and set end flag
if ( GUI.Button(new Rect ( (Screen.width/2)-180, (Screen.height/2)-60, 350, 60), " I will bring her Save") ) {
bl_conversation_complete = true;
}
}
}
else{
// bl conversation complete is now true
// Display text indicating we have spoken
GUI.Label(new Rect ( (Screen.width/2)-180, (Screen.height/2)-60, 350, 50), st_NPC_return_text);
}
}
}// ---
}// -----
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Camera Controls Need Help 1 Answer