so i instantiate and lerp the gameobject prefab , then i destroy it and when i want to do it again the instantiated gameobject is already “lerped”
here is the code :
public GameObject A;
public GameObject B;
GameObject C;
private float currentLerpTime = 0f ;
private float lerpTime = 1f;
private Vector3 StartPos;
private Vector3 EndPos;
void Start () {
StartPos = A.transform.position;
EndPos = A.transform.position + new Vector3(0,10,0);
}
public void Cast()
{
C = Instantiate (B, A.transform.position , new Quaternion(0,0,0,0) ) as GameObject;
C.name = "_fired";
}
public void Lerp (GameObject _fired)
{
if (_fired != null) {
currentLerpTime += Time.deltaTime;
if (currentLerpTime >= lerpTime)
currentLerpTime = lerpTime;
float perc = currentLerpTime / lerpTime;
_fired.transform.position = Vector3.Lerp (StartPos, EndPos, perc);
Destroy (GameObject.Find ("_fired"), 6f);
}
}
void Update () {
Lerp (C);
}
}