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

Need help modifing a working java script

$
0
0
Hi guys, This script work great to open doors but what do I have to do to tell the below door script to open 90* up instead of 90* to the side like it is now. I would like to open a chest using a copy this same script but changing the direction it opens. var OpenSound : AudioClip; var CloseSound : AudioClip; var smooth = 2.0; var DoorOpenAngle = 90.0; private var open : boolean; private var enter : boolean; private var defaultRot : Vector3; private var openRot : Vector3; function Start(){ defaultRot = transform.eulerAngles; openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z); } //Main function function Update (){ if(open){ //Open door transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth); }else{ //Close door transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * smooth); } if(Input.GetKeyDown("e") && enter){ open = !open; if(open){ audio.clip = OpenSound; }else{ audio.clip = CloseSound; } audio.Play(); } } function OnGUI(){ if(enter){ GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Press E to Open/Close"); } } //Activate the Main function when player is near the door function OnTriggerEnter (other : Collider){ if (other.gameObject.tag == "Player") { enter = true; } } //Deactivate the Main function when player is go away from door function OnTriggerExit (other : Collider){ if (other.gameObject.tag == "Player") { enter = 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>