72 lines
1.7 KiB
C#
72 lines
1.7 KiB
C#
using PhysicsTools;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Scene4Events : MonoBehaviour
|
|
{
|
|
public Winch winch;
|
|
|
|
public Text txtStatus;
|
|
|
|
public Text txtHelp;
|
|
|
|
private void Start()
|
|
{
|
|
string text = "Camera Control\r\nDrag Mouse To Rotate\r\nArrow Keys and Page Up/Down to move\r\n\r\n'Space': Throw a ball in direction of camera\r\n'r': Reset the scene\r\n'e': Increase brake torque\r\n'd': Decrease brake torque\r\n'q': Increase heave torque\r\n'a': Decrease heave torque";
|
|
txtHelp.text = text;
|
|
}
|
|
|
|
private void changeBrakeForce(float delta)
|
|
{
|
|
winch.brakeForce += delta;
|
|
if (winch.brakeForce < 0f)
|
|
{
|
|
winch.brakeForce = 0f;
|
|
}
|
|
}
|
|
|
|
private void changeHeaveForce(float delta)
|
|
{
|
|
winch.heaveTorque += delta;
|
|
if (winch.heaveTorque < 0f)
|
|
{
|
|
winch.heaveTorque = 0f;
|
|
}
|
|
else if (winch.heaveTorque > 10000f)
|
|
{
|
|
winch.heaveTorque = 10000f;
|
|
}
|
|
}
|
|
|
|
private string format(float num)
|
|
{
|
|
return num.ToString("0.00");
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKey(KeyCode.E))
|
|
{
|
|
changeBrakeForce(50f);
|
|
}
|
|
else if (Input.GetKey(KeyCode.D))
|
|
{
|
|
changeBrakeForce(-50f);
|
|
}
|
|
if (Input.GetKey(KeyCode.Q))
|
|
{
|
|
changeHeaveForce(50f);
|
|
}
|
|
else if (Input.GetKey(KeyCode.A))
|
|
{
|
|
changeHeaveForce(-50f);
|
|
}
|
|
string text = "Brake Torque: " + format(winch.brakeForce * winch.radius) + "\r\nHeave Torque: " + format(winch.heaveTorque) + "\r\nTension Torque: " + format(winch.tensionTorque) + "\r\nRPM: " + format(winch.rpm);
|
|
txtStatus.text = text;
|
|
Quaternion localRotation = winch.gameObject.transform.localRotation;
|
|
Quaternion quaternion = Quaternion.AngleAxis(winch.rpm / 60f * 2f * 3.14159f, new Vector3(0f, 0f, -1f));
|
|
localRotation = quaternion * localRotation;
|
|
winch.gameObject.transform.rotation = localRotation;
|
|
}
|
|
}
|