Files
XRLib/Assets/FreeForkLift/Scripts/ForkController.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2025-09-26 18:08:07 +09:00
using UnityEngine;
using System.Collections;
public class ForkController : MonoBehaviour {
public Transform fork;
public Transform mast;
public float speedTranslate; //Platform travel speed
public Vector3 maxY; //The maximum height of the platform
public Vector3 minY; //The minimum height of the platform
public Vector3 maxYmast; //The maximum height of the mast
public Vector3 minYmast; //The minimum height of the mast
private bool mastMoveTrue = false; //Activate or deactivate the movement of the mast
// Update is called once per frame
void FixedUpdate () {
Debug.Log(mastMoveTrue);
if(fork.transform.localPosition.y >= maxYmast.y && fork.transform.localPosition.y < maxY.y)
{
mastMoveTrue = true;
}
else
{
mastMoveTrue = false;
}
if (fork.transform.localPosition.y <= maxYmast.y)
{
mastMoveTrue = false;
}
if (Input.GetKey(KeyCode.PageUp))
{
//fork.Translate(Vector3.up * speedTranslate * Time.deltaTime);
fork.transform.localPosition = Vector3.MoveTowards(fork.transform.localPosition, maxY, speedTranslate * Time.deltaTime);
if(mastMoveTrue)
{
mast.transform.localPosition = Vector3.MoveTowards(mast.transform.localPosition, maxYmast, speedTranslate * Time.deltaTime);
}
}
if (Input.GetKey(KeyCode.PageDown))
{
fork.transform.localPosition = Vector3.MoveTowards(fork.transform.localPosition, minY, speedTranslate * Time.deltaTime);
if (mastMoveTrue)
{
mast.transform.localPosition = Vector3.MoveTowards(mast.transform.localPosition, minYmast, speedTranslate * Time.deltaTime);
}
}
}
}