Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections; using System.Collections.Generic; using UnityEngine; public class paths : MonoBehaviour { public Transform [] positions; public float speed;// =4.0f; private int actual; private float distancia; private bool fin = false; void Start () { } // Update is called once per frame void Update () { if(actual < positions.Length && fin == false){ float x = positions[actual].position.x; float z = positions[actual].position.z; positions[actual].position = new Vector3 (x, transform.position.y, z ); movePath( positions[actual]); } else if(actual < positions.Length && fin) { actual = actual + 1; fin = false; } else{ fin = true; } } private void movePath(Transform po){ float x = transform.position.x - po.position.x; float z = transform.position.z - po.position.z; float disEucl = Mathf.Sqrt(x*x + z*z); distancia = disEucl; if(distancia > 0.05f){ Vector3 pos = Vector3.MoveTowards(transform.position, po.position, speed* Time.deltaTime); GetComponent<Rigidbody>().MovePosition(pos); } else fin = true; } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement