1 using System;
2 using
UnityEngine;
3
4 namespace
UnityStandardAssets.Vehicles.Aeroplane
5 {
6     
public class LandingGear : MonoBehaviour
7     {
8
9         
private enum GearState
10         {
11             Raised = -
1,
12             Lowered =
1
13         }
14
15         
// The landing gear can be raised and lowered at differing altitudes.
16         
// The gear is only lowered when descending, and only raised when climbing.
17
18         
// this script detects the raise/lower condition and sets a parameter on
19         
// the animator to actually play the animation to raise or lower the gear.
20
21         
public float raiseAtAltitude = 40;
22         
public float lowerAtAltitude = 40;
23
24         
private GearState m_State = GearState.Lowered;
25         
private Animator m_Animator;
26         
private Rigidbody m_Rigidbody;
27         
private AeroplaneController m_Plane;
28
29         
// Use this for initialization
30         
private void Start()
31         {
32             m_Plane = GetComponent<AeroplaneController>();
33             m_Animator = GetComponent<Animator>();
34             m_Rigidbody = GetComponent<Rigidbody>();
35         }
36
37
38         
// Update is called once per frame
39         
private void Update()
40         {
41             
if (m_State == GearState.Lowered && m_Plane.Altitude > raiseAtAltitude && m_Rigidbody.velocity.y > 0)
42             {
43                 m_State = GearState.Raised;
44             }
45
46             
if (m_State == GearState.Raised && m_Plane.Altitude < lowerAtAltitude && m_Rigidbody.velocity.y < 0)
47             {
48                 m_State = GearState.Lowered;
49             }
50
51             
// set the parameter on the animator controller to trigger the appropriate animation
52             m_Animator.SetInteger(
"GearState", (int) m_State);
53         }
54     }
55 }


Gõ tìm kiếm nhanh...