Good Morning All,
I’ve been going through the standard assets and trying to adjust/add different features to them. One of the features I wanted to change was the ability to manually raise and lower the landing gear. I have reached a script that no longer has any errors, but cannot seem to get the gear to function using the “L” key. It now just stays down, and my guess is it has something to do with the if statements I have for determining the state of the gear. Any help would be most appreciate!
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
namespace UnityStandardAssets.Vehicles.Aeroplane
{
public class LandingGear : MonoBehaviour
{
public UnityEngine.UI.Text altLabel;
private enum GearState
{
Raised = -1,
Lowered = 1
}
// The landing gear can be raised and lowered at differing altitudes.
// The gear is only lowered when descending, and only raised when climbing.
// this script detects the raise/lower condition and sets a parameter on
// the animator to actually play the animation to raise or lower the gear.
public float raiseAtAltitude = 40;
public float lowerAtAltitude = 40;
private GearState m_State = GearState.Lowered;
private Animator m_Animator;
private Rigidbody m_Rigidbody;
private AeroplaneController m_Plane;
// Use this for initialization
private void Start()
{
m_Plane = GetComponent();
m_Animator = GetComponent();
m_Rigidbody = GetComponent();
}
// Update is called once per frame
private void Update()
{
float alt = m_Plane.Altitude;
altLabel.text = alt.ToString(“Alt: 000ft”);
if (m_State == GearState.Lowered)
{
if (CrossPlatformInputManager.GetButton(“l”))
{
m_State = GearState.Raised;
}
}
if (m_State == GearState.Raised)
{
if (CrossPlatformInputManager.GetButton(“l”))
{
m_State = GearState.Lowered;
}
}
// set the parameter on the animator controller to trigger the appropriate animation
m_Animator.SetInteger(“GearState”, (int) m_State);
}
}
}