c# - SetActive GameObject to true not working in Unity 5 -
well work unity 5. i'm create dialogue interaction other object. when player near of object press return key interaction.
the panel dialogue start disabled setactive(false).
in method update when player near other object , press return key , panel setactive(true) , panel not enabled , don't know why. please help.
thanks...
using unityengine; using system.collections; using unityengine.ui; [requirecomponent(typeof(text))] public class dialogue : monobehaviour { private text _textcomponent; public string[] dialoguestrings; public float secondsbetweencharacters = 0.15f; public float characterratemultiplier = 0.5f; public keycode dialogueinput = keycode.return; private bool _isstringbeingrevealed = false; private bool _isdialogueplaying = false; private bool _isendofdialogue = false; public gameobject continueicon; public gameobject stopicon; public gameobject panel; //vector3 thirdpersoncontroller = gameobject.find("thirdpersoncontroller").transform.position; public gameobject thirdpersoncontroller; // use initialization void start () { _textcomponent = getcomponent<text>(); _textcomponent.text = ""; panel.setactive(false); hideicons(); } // update called once per frame void update () { if (thirdpersoncontroller.transform.position.z > 37.6 && thirdpersoncontroller.transform.position.z < 38.8) { if (input.getkeydown (keycode.return)) { panel.setactive(true); if (!_isdialogueplaying) { _isdialogueplaying = true; startcoroutine (startdialogue ()); } }
there 4 possible reasons (with solution)
your condition not true
thirdpersoncontroller.transform.position.z > 37.6 && thirdpersoncontroller.transform.position.z < 38.8
log after condition, if true , problem still persist then,
check function (startdialogue ()) not deactivating panel suddently. (if not case, then)
is other script not making panel deactivate? if not true
then, problem panel child of inactive gameobject. can check unity docs of setactive
note gameobject may inactive because parent not active.
note: these kind of questions based on debugging (thats why answer in debugging manner) recommend learn debugging skill in order become successful programmer.
Comments
Post a Comment