本文共 1235 字,大约阅读时间需要 4 分钟。
private GameObject image; //设置图片private RawImage rawImage;//设置rawimagepublic float speed = 3f;//屏幕是否要逐渐清晰(默认是需要的)private bool isclear = true;//屏幕是否需要逐渐变暗(默认是不需要的)private bool isblack = false;public override void Awake(){ base.Awake(); image = this.gameObject; rawImage = this.GetComponent();}/// /// 淡入效果/// public void fadetoClear(){ rawImage.color=Color.Lerp(rawImage.color,Color.clear, speed*Time.deltaTime);}////// 淡出效果/// public void fadetoBlack(){ rawImage.color = Color.Lerp(rawImage.color, Color.black, speed * Time.deltaTime);}public void SceneToClear(){ fadetoClear(); if (rawImage.color.a<0.05f) { rawImage.color=Color.clear; rawImage.enabled = false; isclear = false; }}public void SceneToBlack(){ rawImage.enabled = true; fadetoBlack(); if (rawImage.color.a > 0.95f) { rawImage.color = Color.black; isblack = true; }}////// 设置场景的淡入/// public void setSceneToClear(){ isclear = true; isblack = false;}////// 设置场景的淡出/// public void setSceneToBlack(){ isclear = false; isblack = true;}void Update () { if (isclear) { SceneToClear(); } else if (isblack) { SceneToBlack(); } }
转载地址:http://ebrxo.baihongyu.com/