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

  1. using UnityEngine;
  2. using System.Collections;
  3. public class movebetween : MonoBehaviour {
  4. public GameObject start;
  5. public GameObject end;
  6. public float distance;
  7. private Vector3 startPos;
  8. private Vector3 endPos;
  9. void Start(){
  10. startPos = start.transform.position;
  11. endPos = end.transform.position;
  12. distance = Vector3.Distance (startPos, endPos) / Vector3.Distance (gameObject.transform.position, startPos);
  13. }
  14. // Update is called once per frame
  15. void Update () {
  16. transform.position = startPos + (endPos - startPos) / distance;
  17. }
  18. void FixedUpdate(){
  19. distance = Vector3.Distance (startPos, endPos) / Vector3.Distance (gameObject.transform.position, startPos);
  20. }
  21. }