修改水
This commit is contained in:
@@ -1,53 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Obi;
|
||||
|
||||
namespace Obi.Samples
|
||||
[RequireComponent(typeof(ObiRope))]
|
||||
public class CursorController : MonoBehaviour
|
||||
{
|
||||
[RequireComponent(typeof(ObiRope))]
|
||||
public class CursorController : MonoBehaviour
|
||||
|
||||
ObiRopeCursor cursor;
|
||||
ObiRope rope;
|
||||
public float minLength = 0.1f;
|
||||
public float speed = 1;
|
||||
|
||||
// Use this for initialization
|
||||
void Start ()
|
||||
{
|
||||
public float minLength = 0.1f;
|
||||
public float speed = 1;
|
||||
|
||||
private ObiRopeCursor cursor;
|
||||
private ObiRope rope;
|
||||
|
||||
void OnEnable()
|
||||
rope = GetComponent<ObiRope>();
|
||||
cursor = GetComponent<ObiRopeCursor>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update ()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.W) && cursor != null)
|
||||
{
|
||||
rope = GetComponent<ObiRope>();
|
||||
cursor = GetComponent<ObiRopeCursor>();
|
||||
}
|
||||
if (rope.restLength > minLength)
|
||||
cursor.ChangeLength(rope.restLength - speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
void Update()
|
||||
if (Input.GetKey(KeyCode.S) && cursor != null)
|
||||
{
|
||||
float change = 0;
|
||||
cursor.ChangeLength(rope.restLength + speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.W) && cursor != null)
|
||||
{
|
||||
change -= speed * Time.deltaTime;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.A)){
|
||||
rope.transform.Translate(Vector3.left * Time.deltaTime,Space.World);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.S) && cursor != null)
|
||||
{
|
||||
change += speed * Time.deltaTime;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.D)){
|
||||
rope.transform.Translate(Vector3.right * Time.deltaTime,Space.World);
|
||||
}
|
||||
|
||||
if (rope.restLength + change < minLength)
|
||||
change = minLength - rope.restLength;
|
||||
|
||||
cursor.ChangeLength(change);
|
||||
|
||||
if (Input.GetKey(KeyCode.A))
|
||||
{
|
||||
rope.transform.Translate(Vector3.left * Time.deltaTime, Space.World);
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.D))
|
||||
{
|
||||
rope.transform.Translate(Vector3.right * Time.deltaTime, Space.World);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user