|
@ -3,17 +3,23 @@ using System.Collections; |
|
|
|
|
|
|
|
|
public class movebetween : MonoBehaviour { |
|
|
public class movebetween : MonoBehaviour { |
|
|
|
|
|
|
|
|
public GameObject start; |
|
|
|
|
|
public GameObject end; |
|
|
|
|
|
|
|
|
public GameObject[] points; |
|
|
|
|
|
//public GameObject end;
|
|
|
|
|
|
|
|
|
public float distance; |
|
|
public float distance; |
|
|
|
|
|
public float changeDis; |
|
|
|
|
|
|
|
|
private Vector3 startPos; |
|
|
private Vector3 startPos; |
|
|
private Vector3 endPos; |
|
|
private Vector3 endPos; |
|
|
|
|
|
public int count = 0; |
|
|
|
|
|
public bool useCustomRotation = false; |
|
|
|
|
|
|
|
|
|
|
|
private Rigidbody rb; |
|
|
|
|
|
|
|
|
void Start(){ |
|
|
void Start(){ |
|
|
startPos = start.transform.position; |
|
|
|
|
|
endPos = end.transform.position; |
|
|
|
|
|
|
|
|
rb = gameObject.GetComponent<Rigidbody> (); |
|
|
|
|
|
startPos = points[count].transform.position; |
|
|
|
|
|
endPos = points[count+1].transform.position; |
|
|
|
|
|
|
|
|
distance = Vector3.Distance (startPos, endPos) / Vector3.Distance (gameObject.transform.position, startPos); |
|
|
distance = Vector3.Distance (startPos, endPos) / Vector3.Distance (gameObject.transform.position, startPos); |
|
|
} |
|
|
} |
|
@ -21,12 +27,35 @@ public class movebetween : MonoBehaviour { |
|
|
// Update is called once per frame
|
|
|
// Update is called once per frame
|
|
|
void Update () { |
|
|
void Update () { |
|
|
|
|
|
|
|
|
transform.position = startPos + (endPos - startPos) / distance; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//transform.position = startPos + (endPos - startPos) / distance;
|
|
|
|
|
|
if (!useCustomRotation) { |
|
|
|
|
|
Vector3 lookAtTarget = endPos; |
|
|
|
|
|
lookAtTarget.y = transform.position.y; |
|
|
|
|
|
transform.LookAt (lookAtTarget); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void FixedUpdate(){ |
|
|
void FixedUpdate(){ |
|
|
|
|
|
if (Vector3.Distance (gameObject.transform.position, startPos) <= changeDis && count != 0) { |
|
|
|
|
|
count--; |
|
|
|
|
|
startPos = points[count].transform.position; |
|
|
|
|
|
endPos = points[count+1].transform.position; |
|
|
|
|
|
} |
|
|
|
|
|
if (Vector3.Distance (gameObject.transform.position, endPos) <= changeDis && count + 1 != points.Length) { |
|
|
|
|
|
count++; |
|
|
|
|
|
startPos = points[count].transform.position; |
|
|
|
|
|
endPos = points[count+1].transform.position; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
distance = Vector3.Distance (startPos, endPos) / Vector3.Distance (gameObject.transform.position, startPos); |
|
|
distance = Vector3.Distance (startPos, endPos) / Vector3.Distance (gameObject.transform.position, startPos); |
|
|
|
|
|
|
|
|
|
|
|
Vector3 newPos = gameObject.transform.position; |
|
|
|
|
|
newPos.x = startPos.x + (endPos.x - startPos.x) / distance; |
|
|
|
|
|
newPos.y = startPos.y + (endPos.y - startPos.y) / distance; |
|
|
|
|
|
|
|
|
|
|
|
rb.MovePosition (newPos); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |