|
|
@ -0,0 +1,32 @@ |
|
|
|
using UnityEngine; |
|
|
|
using System.Collections; |
|
|
|
|
|
|
|
public class movebetween : MonoBehaviour { |
|
|
|
|
|
|
|
public GameObject start; |
|
|
|
public GameObject end; |
|
|
|
|
|
|
|
public float distance; |
|
|
|
|
|
|
|
private Vector3 startPos; |
|
|
|
private Vector3 endPos; |
|
|
|
|
|
|
|
void Start(){ |
|
|
|
startPos = start.transform.position; |
|
|
|
endPos = end.transform.position; |
|
|
|
|
|
|
|
distance = Vector3.Distance (startPos, endPos) / Vector3.Distance (gameObject.transform.position, startPos); |
|
|
|
} |
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update () { |
|
|
|
|
|
|
|
transform.position = startPos + (endPos - startPos) / distance; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void FixedUpdate(){ |
|
|
|
distance = Vector3.Distance (startPos, endPos) / Vector3.Distance (gameObject.transform.position, startPos); |
|
|
|
} |
|
|
|
} |