using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class fogomov : MonoBehaviour {
private Vector3 PosA;
private Vector3 PosB;
private Vector3 nexp;
[SerializeField]
private float speed;
[SerializeField]
private Transform childtransform;
[SerializeField]
private Transform transformB;
// Use this for initialization
void Start () {
PosA = childtransform.localPosition;
PosB = transformB.localPosition;
nexp = PosB;
}
// Update is called once per frame
void Update () {
Move();
}
private void Move()
{
childtransform.localPosition = Vector3.MoveTowards(childtransform.localPosition, nexp, speed * Time.deltaTime);
if (Vector3.Distance(childtransform.localPosition, nexp) <= 0.01)
{
Changedestination();
}
}
private void Changedestination()
{
nexp = nexp != PosA ? PosA : PosB;
}
}
i got this script to move an object but I wanted it every time the object arrives at a destination it turns to the contrary someone can help me I can not do