Hi I am Object Pooling astereroids, but when they suddenly pop up it looks bad. So I have tryied to fade it with lerping transperency, which works but its taking a lot of performance.
Calling a function
void OnTriggerEnter(Collider other) {
other.transform.position = GeneratedPosition();// other are Asteriods, Reposition asteriods
other.GetComponent<Fade>().Reposition ();//Calling a a component which has every asteriod
}
Fade Script
public void Reposition () {
fade = true;
valToBeLerped = 0;
tParam = 0;
}
// Update is called once per frame
void Update () {
if(fade){
if (tParam < 1) {
tParam += Time.deltaTime * speed; //This will increment tParam based on Time.deltaTime multiplied by a speed multiplier
valToBeLerped = Mathf.Lerp(0, 1, tParam);
Rend = GetComponent<Renderer>();
color.a =valToBeLerped;
Rend.material.color =color;
}
}
}
Is there way to optimaze it or do it better?
Thanks