Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

How do I access a variable/class from a C# file in a JS file?

$
0
0
I am trying to access the currentState variable from my 'TextManagerLvl1.cs' script which is located in the same place, however I get the below error.> Assets/Levels/Lvl1/Scripts/Continue.js(11,12):> BCE0005: Unknown identifier:> 'TextManagerLvl1'. (This is shown for all of the instances of "TextManagerLvl1" (so 3 times)) I believe that the two scripts aren't linking properly, and I am unsure how to link them properly. Any help is greatly appreciated!! My 'Continue.js' script is below. import UnityEngine.SceneManagement; var SceneName : String; var Click : AudioClip; var ButtonTrueAnimation : Animation; var ButtonFalseAnimation : Animation; var ButtonContinueAnimation : Animation; function Play () { if(TextManagerLvl1.currentState == "trueState") { TrueState(); } else if(TextManagerLvl1.currentState == "falseState") { FalseState(); } else if(TextManagerLvl1.currentState == "continueState") { ContinueState(); } } function TrueState () { GetComponent.().Play(); ButtonTrueAnimation.GetComponent.().Play(); LoadSpecifiedScene(); } function FalseState () { GetComponent.().Play(); ButtonFalseAnimation.GetComponent.().Play(); LoadSpecifiedScene(); } function ContinueState () { GetComponent.().Play(); ButtonContinueAnimation.GetComponent.().Play(); LoadSpecifiedScene(); } function LoadSpecifiedScene () { yield WaitForSeconds(1); SceneManager.LoadScene(SceneName); } My 'TextManagerLvl1.cs' script is below. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class TextManagerLvl1 : MonoBehaviour { public Text MainText; public Button ButtonTrue; public Button ButtonFalse; public GameObject ButtonContinue; public GameObject ButtonT; public GameObject ButtonF; public bool Correct; public bool False; private enum States { question, trueState, falseState, continueState }; private States myState; void Start () { myState = States.question; } void Update () { if (myState == States.question) {question ();} else if (myState == States.trueState) {trueState ();} else if (myState == States.falseState) {falseState ();} } void OnEnable() { //Typing (delegate {Correct = true;}) after any of the following, it makes that button the correct one ButtonTrue.onClick.AddListener (delegate {Correct = true;}); ButtonFalse.onClick.AddListener (delegate {False = true;}); } void question() { MainText.text = "This is a sentence."; if(Correct == true) {myState = States.trueState;} else if(False == true) {myState = States.falseState;} } void trueState() { MainText.text = "You are correct! :)"; Deactivate (); } void falseState() { MainText.text = "You are wrong! :("; Deactivate (); } void Deactivate() { ButtonContinue.SetActive (true); myState = States.continueState; ButtonT.SetActive (false); ButtonF.SetActive (false); } }

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>