You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
4.3 KiB
107 lines
4.3 KiB
using UniRx; |
|
using UnityEngine; |
|
public class Ladder15Controller : MonoBehaviour |
|
{ |
|
public GameObject ladder_15Up1; |
|
public GameObject ladder_15Up2; |
|
private float ladder_15Up1FlexMaxY = 4.80f; |
|
private float ladder_15Up2FlexMaxY = 5f; |
|
private Vector3 ladder_15Up1Pos; |
|
private Vector3 ladder_15Up2Pos; |
|
private float ladder_15Up1StartY; |
|
private float ladder_15Up2StartY; |
|
private float flexSpeed = 3.0f; |
|
private float rotateSpeed = 60; |
|
private bool ctrlDown = false; |
|
// Start is called before the first frame update |
|
void Start() |
|
{ |
|
ladder_15Up1 = transform.Find("Scene/Ladder15M/LadderUp1").gameObject; |
|
ladder_15Up2 = ladder_15Up1.transform.Find("LadderUp2").gameObject; |
|
|
|
ladder_15Up1Pos = ladder_15Up1.transform.localPosition; |
|
ladder_15Up2Pos = ladder_15Up2.transform.localPosition; |
|
ladder_15Up1StartY = ladder_15Up1Pos.y; |
|
ladder_15Up2StartY = ladder_15Up2Pos.y; |
|
|
|
Observable.EveryLateUpdate() |
|
.Subscribe(_ => Control()).AddTo(gameObject); |
|
} |
|
|
|
|
|
void Control() |
|
{ |
|
if (SelectionManager.IsContains(gameObject)) |
|
{ |
|
if (Input.GetKeyDown(PowerManager.Instance.fn)) |
|
ctrlDown = true; |
|
|
|
if (Input.GetKeyUp(PowerManager.Instance.fn)) |
|
ctrlDown = false; |
|
|
|
float y1 = ladder_15Up1.transform.localPosition.y; |
|
float y2 = ladder_15Up2.transform.localPosition.y; |
|
if (y2 == ladder_15Up2StartY)//第二节拉梯没有伸出的状态下才能控制第一节拉梯 |
|
{ |
|
if (y1 >= ladder_15Up1StartY && y1 <= ladder_15Up1FlexMaxY) |
|
{ |
|
if (ctrlDown && Input.GetKey(PowerManager.Instance.up)) |
|
{ |
|
float detaY = Time.deltaTime * flexSpeed; |
|
ladder_15Up1.transform.localPosition = new Vector3(ladder_15Up1Pos.x, |
|
(y1 + detaY) > ladder_15Up1FlexMaxY ? ladder_15Up1FlexMaxY : (y1 + detaY), |
|
ladder_15Up1Pos.z); |
|
} |
|
|
|
if (ctrlDown && Input.GetKey(PowerManager.Instance.down)) |
|
{ |
|
float detaY = Time.deltaTime * flexSpeed; |
|
ladder_15Up1.transform.localPosition = new Vector3(ladder_15Up1Pos.x, |
|
(y1 - detaY) < ladder_15Up1StartY ? ladder_15Up1StartY : (y1 - detaY), |
|
ladder_15Up1Pos.z); |
|
} |
|
} |
|
} |
|
if (y1 == ladder_15Up1FlexMaxY)//第一节拉梯完全伸出的状态下才能控制第二节拉梯 |
|
{ |
|
if (y2 >= ladder_15Up2StartY && y2 <= ladder_15Up2FlexMaxY) |
|
{ |
|
if (ctrlDown && Input.GetKey(PowerManager.Instance.up)) |
|
{ |
|
float detaY = Time.deltaTime * flexSpeed; |
|
ladder_15Up2.transform.localPosition = new Vector3(ladder_15Up2Pos.x, |
|
(y2 + detaY) > ladder_15Up2FlexMaxY ? ladder_15Up2FlexMaxY : (y2 + detaY), |
|
ladder_15Up2Pos.z); |
|
} |
|
if (ctrlDown && Input.GetKey(PowerManager.Instance.down)) |
|
{ |
|
float detaY = Time.deltaTime * flexSpeed; |
|
ladder_15Up2.transform.localPosition = new Vector3(ladder_15Up2Pos.x, |
|
(y2 - detaY) < ladder_15Up2StartY ? ladder_15Up2StartY : (y2 - detaY), |
|
ladder_15Up2Pos.z); |
|
|
|
} |
|
} |
|
} |
|
|
|
if (Input.GetKey(PowerManager.Instance.leftR)) |
|
{ |
|
transform.Rotate(0, -Time.deltaTime * rotateSpeed, 0, Space.World); |
|
} |
|
if (Input.GetKey(PowerManager.Instance.rightR)) |
|
{ |
|
transform.Rotate(0, Time.deltaTime * rotateSpeed, 0, Space.World); |
|
} |
|
|
|
if (!ctrlDown && Input.GetKey(PowerManager.Instance.down)) |
|
{ |
|
transform.Rotate(Time.deltaTime * rotateSpeed, 0, 0); |
|
} |
|
|
|
if (!ctrlDown && Input.GetKey(PowerManager.Instance.up)) |
|
{ |
|
transform.Rotate(-Time.deltaTime * rotateSpeed, 0, 0); |
|
} |
|
} |
|
} |
|
}
|
|
|