using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveNavi : MonoBehaviour
{
public Transform destinationTransform
public float speed;
public float distanceToStop;
public float lerpTime;
public static bool naviChildOfHand = false;
private GameObject rig_f_middle;
private bool changeNaviChild = false;
// Start is called before the first frame update
void Start()
{
rig_f_middle = GameObject.Find("rig_f_middle.02.R");
}
// Update is called once per frame
void Update()
{
if (IKControl.startMovingNAVI == true)
{
var v = rig_f_middle.transform.position - transform.position;
if (v.magnitude < 0.001f)
{
//this.transform.parent = rig_f_middle.transform;
//this.enabled = false;
naviChildOfHand = true;
changeNaviChild = true;
return;
}
Vector3 moveDir = v.normalized;
transform.position += moveDir * speed * Time.deltaTime;
}
if(changeNaviChild == true)
{
this.transform.position = Mathf.Lerp(this.transform.position,
destinationTransform.position, lerpTime * Time.deltaTime);
}
}
}
Instead just changing the object child to another parent with this line :
this.transform.parent = rig_f_middle.transform;
I have duplicated the object in two places this transform when the game start it's child of a parent and destinationTransform is another copy of the transform object and I want to use the Mathf Lerp to smooth switch from the transform to the destinationTransform.
Here is a screenshot :
I marked with red circle the destination name NAVI Destination it's the same object as the NAVI Original.
And I want to use Lerp to smooth change between the original to the destination so the slowly the original will become disable and the destination will become enabled somehow.
The main goal is to make a smooth transition changing the NAVI as child from one parent to another parent.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…