I am trying to create level prograss bar, here is the script to fill the Slider along with ball when its moving towards finish line , here finish line is prefab clone which is randomly instantiated at different position. but as expected finishTransform using position(0, 0, 0) from prefab not from the clone. how can i retrieve the clone into the script when it is instantiated? here is the Progressbar Script :
[SerializeField] Transform ballTransform;
[SerializeField] Transform finishTransform;
[SerializeField] Slider slider;
float maxDistance;
void Start()
{
maxDistance = getDistance();
}
void Update()
{
if (ballTransform.position.z <= maxDistance && ballTransform.position.z <= finishTransform.position.z)
{
float distance = 1 - (getDistance() / maxDistance);
setProgress(distance);
}
}
float getDistance()
{
return Vector3.Distance(ballTransform.position, finishTransform.position);
}
void setProgress(float p)
{
slider.value = p;
}
Here is the Platform script where i instantiated the finish line
GameObject finalPlatformInstance = Instantiate(finalPlatform, transform);
finalPlatformInstance.transform.localPosition = new Vector3(0, 0, spawnPosZ);