Greetings all…
So, I have a door open script which I found on here and changed a bit as follows :-
var targeti : Transform;
var playeri : Transform;
var moveSpeed : float = 5.0;
var upMaxDistance : float = 10.0;
var openCloseSound : AudioClip;
private var initPosition : Vector3;
private var openDoor : boolean = false;
function Start() {
initPosition = targeti.transform.position;
}
function Update () {
if (!targeti) {
return;
}
if (!playeri) {
return;
}
if (openDoor == true) {
targeti.position.y = Mathf.Min(upMaxDistance, targeti.position.y+moveSpeed * Time.deltaTime);
}
else {
targeti.position.y = Mathf.Max(initPosition.y, targeti.position.y-moveSpeed * Time.deltaTime);
}
}
function OnTriggerEnter() {
openDoor = true;
audio.PlayOneShot(openCloseSound);
}
function OnTriggerExit() {
yield WaitForSeconds(2);
openDoor = false;
audio.PlayOneShot(openCloseSound);
}
Using this I can define the target of the trigger and the object which triggers it… player or monster etc.
However… when I set the trigger to be my player char… the door works perfectly, but so does a rocket fired by the player…
Is this because the rocket is a child of the player and so is seen as “the player” as well?
Interestingly, if opened by a rocket, it doesn’t close again as I assume that as the rocket is destroyed, it never leaves the trigger to trigger the exit routine.
If so, or if I am completely wrong, how would I go about getting only my player to trigger the door please? Got me baffled this one
Regards
Graham