Quantcast
Channel: Latest Questions by GraviterX
Viewing all articles
Browse latest Browse all 122

Door Script

$
0
0
Hey guys. I have this door script that is supposed to switch between 2 booleans in order to allow the player to open and close the door. Once the door is opened, it switches the openable boolean to the closeable boolean. However, the door opens just fine, and the closeable boolean activates. However, when I press the mouse down again nothing happens. Can OnMouseDown only be used once? I'm not sure what the problem is. Any advice? var closeAnimationFile : String = "door_close_1"; var openSound : AudioClip; var closeSound : AudioClip; var inRange : boolean; var openActive : boolean; var closeActive : boolean; function Start() { openActive = true; closeActive = false; } function OnTriggerEnter() { inRange = true; } function OnTriggerExit() { inRange = false; } function OnMouseDown() { if (openActive==true && inRange == true) { animation.Play(openAnimationFile); audio.clip = openSound; audio.Play(); Debug.Log("Open"); Open(); } if (openActive==false && inRange == true) { return; } if (closeActive==true && inRange == true) { animation.Play(closeAnimationFile); audio.clip = closeSound; audio.Play(); Debug.Log("Close"); Close(); } if (closeActive==false && inRange == true) { return; } } function Open() { openActive = false; closeActive = true; Debug.Log("Set Close Active"); return; } function Close() { openActive = true; closeActive = false; Debug.Log("Set Open Active"); return; }

Viewing all articles
Browse latest Browse all 122

Trending Articles



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