Hi all, pretty new to Unity and the world of coding, I have a javascript that I basically copied from an internet tutorial, to open a door (01) with a switch. This works fine of itself and the animations are all working correctly. The problem is that I have another door (02) which I would like the user to open directly (no switch) by using the same button. Once again the door does what I want it to, with regard to the animations but the pressing of the “Action” button in this case ‘E’ triggers both the doors to open simultaneously, which needless to say I do not want. The sript is added to the switch of door 01 and the hinge of door 02, which parents the door object.
The Character Controller Script and the first door script are copied below, the second door script is identical to the first, apart from the names “door 2” and “open door 2”. I would also like them to play different sounds to each other. Any help would be most appreciated, I have fried enough braincells so far, suspecting that it is to do with the button press, I just can’t figure it out!
Thanks in advance!
Player Script:
static var DistanceFromTarget : float;
var ToTarget : float;
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
ToTarget = hit.distance;
DistanceFromTarget = ToTarget;
}
Door Script:
import UnityEngine.UI;
//varTextDisplay:GameObject;
var TheDistance : float = PlayerCasting.DistanceFromTarget;
var TheDoor1 : GameObject;
var hit : RaycastHit;
function Update () {
TheDistance = PlayerCasting.DistanceFromTarget;
if (Input.GetButtonDown(“Action”))
{
if (TheDistance <=2) {
OpenTheDoor1 ();
}
}
}
/*functionOnMouseOver(){
if(TheDistance<=2){
TextDisplay.GetComponent.().text=“PresstoOpenDoor”;
}
}
functionOnMouseExit(){
TextDisplay.GetComponent.().text=“”;
}
*/
function OpenTheDoor1 () {
var LightHouseDoorShutter : AudioSource = GetComponent.();
LightHouseDoorShutter.Play();
TheDoor1.GetComponent (“Animator”).enabled=true;
yieldWaitForSeconds (6);
TheDoor1.GetComponent (“Animator”).enabled=false;
yieldWaitForSeconds (5);
LightHouseDoorShutter.Play();
TheDoor1.GetComponent (“Animator”).enabled=true;
yieldWaitForSeconds (6);
TheDoor1.GetComponent (“Animator”).enabled=false;
}