//USE Z POSITION RANGE TO CONTROL OPACITY: fullOnZ = -900; //z value where you want opacity to be 100%; fullOffZ = 2700; //z value where you want opacity to be 0%; num = 100-(100*(transform.position[2]+(fullOnZ*-1))/fullOffZ); //this step allows you to keep existing opacity keyframes //by adding our formula result to the existing opacity num = num * (transform.opacity/100); value = num;