- Home /
stop an elevator
I have been monkeying around with the Stealth tutorial which ends with an elevator going up as the scene fades out. I commented out the scene ending stuff to see what happens and the elevator just keeps going. I have been all over the web trying to find a way to have it stop s o i can continue adding to the scene I built with the tutorial. None of the script functions I have found work. At best it snapped the elevator to that position and any script I came across with .Lerp in it unity told me it didn't exist or some such error. I simply want the elevator to stop after goinp up 4 floors so whatever that translates to in unity units ( a player is 2 so 8 or 10? ) anyway. move the elevator slowly ( like it is) but stop and unparent the player so I can get off. I don't know if you need the entire code but here is the part that I have been playing with at the end. I am having lots of fun with this but am stuck ( I managed to modify the enemyAttack script and apply to a health powerup).oh, as you can see I also commented out the camera movement being false so I could still follow the player ( as he snaps to a new location as it currently exists)
void LiftActivation () { // Increment the timer by the amount of time since the last frame. timer += Time.deltaTime;
// If the timer is greater than the amount of time before the lift should start...
if(timer >= timeToLiftStart)
{
// ... stop the player and the camera moving and parent the player to the lift.
playerAnim.SetFloat(hash.speedFloat,0f);
//camMovement.enabled = false;
player.transform.parent = transform;
// Move the lift upwards.
//transform.Translate(Vector3.up * liftSpeed * Time.deltaTime);
// If the audio clip isn't playing...
if(!audio.isPlaying)
// ... play the clip.
audio.Play();
// If the timer is greater than the amount of time before the level should end...
//if(timer >= timeToEndLevel)
// ... call the EndScene function.
// sceneFadeInOut.EndScene();
}
}
}
Answer by rantor88 · Jun 04, 2015 at 02:54 PM
I looked through the internet and found a forum question where someone wanted to stop something from translating. They said that it would be better to define a boolean to dictate when it should stop moving. The question is here.
Anyways, you should try that and see if it stops the elevator, and modify the code to include what you have to do (Unparent the guy, play more music, etc.)