You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
693 B

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);
}
}