- Home /
Question by
jo05099056 · Mar 22, 2018 at 03:28 PM ·
inputfieldelement
Changing Elements based off an Input Field answer
Long story short, heres the code I'm using. I'm trying to make it if a certain set of words are said, you will get different effects. I'm also using the Elements for the text so I was wondering if there was a way for it to detect what is in the Input Field and changing the element accordingly?
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
public class DebateConversation : MonoBehaviour {
public GameObject neutral_Nagito;
public GameObject diffuse_Nagito;
public GameObject hello_Nagito;
public GameObject ponder_Nagito;
public GameObject scold_Nagito;
public GameObject hmmm_Nagito;
public GameObject angry_Nagito;
public GameObject surprised_Nagito;
public GameObject insane_Nagito;
public InputField Contradiction_Text;
public Button NextConv;
public Button PrevConv;
public Button Contradict;
public Canvas Contra_Menu;
public GameObject Ponderosa;
public GameObject Ponderosa_D;
public GameObject D_Trigger;
public Canvas D_Conversation;
public Text textbox;
public UnityStandardAssets.Characters.FirstPerson.FirstPersonController fpc;
int i, j, testJ;
public string[] speeches;
public string[] Contradiction_bullet;
void Start () {
Ponderosa.SetActive (true);
Contra_Menu.enabled = false;
neutral_Nagito.SetActive (false);
diffuse_Nagito.SetActive (false);
hello_Nagito.SetActive (false);
ponder_Nagito.SetActive (false);
scold_Nagito.SetActive (false);
hmmm_Nagito.SetActive (false);
angry_Nagito.SetActive (false);
surprised_Nagito.SetActive (false);
insane_Nagito.SetActive (false);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
D_Conversation.enabled = false;
testJ = j;
Button CDTbtn = Contradict.GetComponent<Button>();
CDTbtn.onClick.AddListener(Contra_TaskOnClick);
Button NXTbtn = NextConv.GetComponent<Button>();
NXTbtn.onClick.AddListener(Next_TaskOnClick);
Button PREbtn = PrevConv.GetComponent<Button>();
PREbtn.onClick.AddListener(Prev_TaskOnClick);
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay(Collider other) {
Debug.Log (other.name);
if (other.name == "Detective Ponderosa" && Input.GetKeyDown (KeyCode.E)) {
Ponderosa.SetActive (false);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
fpc.enabled = false;
D_Conversation.enabled = true;
}
}
void Contra_TaskOnClick () {
}
void Next_TaskOnClick () {
i++;
}
void Prev_TaskOnClick () {
i--;
}
void FixedUpdate() {
string Contradiction_Bullet = Contradiction_Text.text.ToString();
if (D_Conversation.isActiveAndEnabled) {
for (int j = 0; j < speeches [i].Length + 1; j++) {
textbox.text = speeches [i].Substring (0, j);
testJ = j;
}
}
if ((testJ >= speeches[i].Length) && (Input.GetMouseButtonDown(0))) {
i++;
}
if (i == 0) {
hmmm_Nagito.SetActive (true);
}
if (i == 1) {
hmmm_Nagito.SetActive(false);
ponder_Nagito.SetActive (true);
}
if (i == 2) {
ponder_Nagito.SetActive (false);
surprised_Nagito.SetActive (true);
}
if (i == 3) {
if (Contradiction_Bullet == "knife") {
i = 7;
}
}
if (i == 4) {
}
if (i == 5) {
}
if (i == 6) {
surprised_Nagito.SetActive (false);
hmmm_Nagito.SetActive (true);
i = 0;
}
if (i == 7) {
}
if (i == 8) {
}
if (i == 9) {
}
if (i == 10) {
}
if (i == speeches.Length) {
Ponderosa.SetActive (true);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
fpc.enabled = true;
D_Conversation.enabled = false;
}
if ((i == speeches.Length) && (fpc.enabled = true)){
i=0;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Playing animation elements not working 2 Answers
How do you Get Variables with 2 or more Elements? 2 Answers
Issue removing element from List 0 Answers
How to save InputField value? 1 Answer
How to prevent Input Field firing End Edit on change of focus? 2 Answers