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.
76 lines
2.6 KiB
76 lines
2.6 KiB
using UniRx; |
|
using UnityEngine; |
|
public class Ladder6Controller : MonoBehaviour |
|
{ |
|
public GameObject ladder_6Up; |
|
private float ladder_6UpFlexMaxY = 3.27f; |
|
private Vector3 ladder_6UpPos; |
|
private float ladder_6UpStartY; |
|
private float flexSpeed = 3.0f; |
|
private float rotateSpeed = 60; |
|
private bool ctrlDown = false; |
|
// Start is called before the first frame update |
|
void Start() |
|
{ |
|
ladder_6Up = transform.Find("Scene/Ladder6M/LadderUp").gameObject; |
|
ladder_6UpPos = ladder_6Up.transform.localPosition; |
|
ladder_6UpStartY = ladder_6UpPos.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 y = ladder_6Up.transform.localPosition.y; |
|
|
|
if (y >= ladder_6UpStartY && y <= ladder_6UpFlexMaxY) |
|
{ |
|
if (ctrlDown && Input.GetKey(PowerManager.Instance.up)) |
|
{ |
|
float detaY = Time.deltaTime * flexSpeed; |
|
ladder_6Up.transform.localPosition = new Vector3(ladder_6UpPos.x, (y + detaY) > ladder_6UpFlexMaxY ? ladder_6UpFlexMaxY : (y + detaY), ladder_6UpPos.z); |
|
} |
|
|
|
if (ctrlDown && Input.GetKey(PowerManager.Instance.down)) |
|
{ |
|
float detaY = Time.deltaTime * flexSpeed; |
|
ladder_6Up.transform.localPosition = new Vector3(ladder_6UpPos.x, |
|
(y - detaY) < ladder_6UpStartY ? ladder_6UpStartY : (y - detaY), |
|
ladder_6UpPos.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); |
|
} |
|
} |
|
} |
|
}
|
|
|