72 lines
1.7 KiB
C#
72 lines
1.7 KiB
C#
using PhysicsTools;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Scene5Events : MonoBehaviour
|
|
{
|
|
public Rope rope;
|
|
|
|
public GameObject cube;
|
|
|
|
public Text txtHelp;
|
|
|
|
public float speed = 0.01f;
|
|
|
|
public float incDist = 1f;
|
|
|
|
public float hitForce = 1f;
|
|
|
|
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'f': Move cube forward\r\n'b': Move cube backward\r\n's': Stop moving cube";
|
|
txtHelp.text = text;
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
Vector3 vector = rope.controlPoints[rope.controlPoints.Count - 1].globalPos(rope);
|
|
Vector3 position = cube.transform.position;
|
|
float magnitude = (position - vector).magnitude;
|
|
float length = rope.getLength();
|
|
if (length - magnitude < incDist)
|
|
{
|
|
rope.changeLength(cube.GetComponent<MoveCube>().velocity.magnitude * Time.fixedDeltaTime);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.F))
|
|
{
|
|
cube.GetComponent<MoveCube>().velocity = new Vector3(-1f, 0f, 0f);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.B))
|
|
{
|
|
cube.GetComponent<MoveCube>().velocity = new Vector3(1f, 0f, 0f);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.S))
|
|
{
|
|
cube.GetComponent<MoveCube>().velocity = new Vector3(0f, 0f, 0f);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.H))
|
|
{
|
|
cube.GetComponent<Rigidbody>().AddForce(new Vector3(0f - hitForce, 0f, 0f));
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.I))
|
|
{
|
|
rope.rate = speed;
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.D))
|
|
{
|
|
if (rope.getSegments().Count > 2)
|
|
{
|
|
rope.rate = 0f - speed;
|
|
}
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.S))
|
|
{
|
|
rope.rate = 0f;
|
|
}
|
|
}
|
|
}
|