I have some problems.
What i want to do is one the player is on the Platform the first Platform in the Hierarchy and then click the Button lift up the Elevator and Down none stop.
In the Hierarchy i have a ThirdPersonController and then i added an empty GameObject. I renamed it’s name to Elevator.
Then under Elevator as childs i created two Cubes and renamed them to Platform and Platform1.
The first Platform is the floor where the player will stand on. The second Platform1 is what holding the Button.
And the Button is a Capsule i changed it’s position to be on the Platform1.
This screenshot show it also the script i called it Lift that attached to the Button:
Now i clicked selected the Elevator and then in the menu i did: Window > Animation
And i created two animation alled them: Up and Down.
Both animation of the Elevator(GameObject) moving up and down.
But this is my first problem:
When i attached the script to the Button i needed to add Animation component to the Elevator.
Then i needed to add to the Animation component on the Elevator dragged to it the Up animation asset.
Then i needed to check and make the Up clip animation to be Legacy.
After doing it now when i make: Window > Animation i see only the Down animation clip once i did the Up to be Legacy it’s gone from the Animation window.
Another problem i’m getting now error saying it can’t find the Down clip and that my script trying to access it but can’t find it. But where should i add it to ? The Animation in the Elevator already have the Up clip as animation.
Second problem when the player ThirdPersonController is standing on the Platform and i click the button it’s lifting up with the player the whole this is shaking/stuttering.
Another problem is that i need to click twice the button to make it lifting up. One click does nothing. Only the second click trigger it.
This is my script:
using UnityEngine;
using System.Collections;
public class Lift : MonoBehaviour {
private bool pressedButton = false;
private bool isElevatorUp = false;
GameObject target;
void OnMouseOver()
{
pressedButton = true;
}
void OnMouseExit()
{
pressedButton = false;
}
void OnMouseDown()
{
if(isElevatorUp == false)
{
target = GameObject.Find("Elevator");
target.GetComponent<Animation>().Play("Up");
isElevatorUp = true;
}
else
{
target = GameObject.Find("Elevator");
target.GetComponent<Animation>().Play("Down");
isElevatorUp = false;
}
}
void OnGUI()
{
if(pressedButton == true)
{
GUI.Box(new Rect(300, 300, 200, 20), "Press to use lift!");
}
}
}
And last this is a short video i recorded showing the error and the stuttering and that the Up clip is gone from the Animation window: