Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class ToPointAndBack : MonoBehaviour
- {
- private Transform Self;
- public Vector3 StartVector3;
- public Vector3 TargetVector3;
- private Vector3 MovingVector3;
- public float Speed;
- void Start()
- {
- Self = GetComponent<Transform>();
- StartVector3 = Self.position;
- MovingVector3 = TargetVector3;
- }
- // Update is called once per frame
- void Update ()
- {
- MoveFromAtoB();
- }
- private void MoveFromAtoB()
- {
- Self.Translate((MovingVector3 - Self.position).normalized * Speed * Time.deltaTime);
- //Проверка на преодоление координат точки Б объектом и присвоение координат точки А вектору движения
- if (Self.position.x > TargetVector3.x || Self.position.y > TargetVector3.y || Self.position.z > TargetVector3.z)
- MovingVector3 = StartVector3;
- //Проверка на преодоление координат точки А объектом и присвоение координат точки Б вектору движения
- if (Self.position.x < StartVector3.x || Self.position.y < StartVector3.y || Self.position.z < StartVector3.z)
- MovingVector3 = TargetVector3;
- }
- }
Add Comment
Please, Sign In to add comment