失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Unity VR学习:第一人称射击游戏(1)

Unity VR学习:第一人称射击游戏(1)

时间:2019-12-25 11:52:33

相关推荐

Unity VR学习:第一人称射击游戏(1)

Unity VR学习:第一人称射击游戏(1)

1.封装标签和场景淡入淡出效果实现

(1) 封装标签

1.标签有Player,Enemy,GameController,Fader(画布),MainCamera

2.使用const常量进行封装:

const:声明某个常量字段或常量局部变量。

注意:常量字段和常量局部变量不是变量并且不能修改

利用const管理游戏标签

(2) 场景淡入淡出

1.本使用GUITexture,但版本已弃用。若直接在空物体中添加image组件将不会显示,使用UI的Panel。

2.挂载脚本FadeInOut: ①.在Start中使用this.getCompoent获取组件 ②.主要使用lerp方法实现淡入淡出

public float fadeSpeed = 1.5f;private bool sceneStarting = true;private Image tex;void Start(){tex = this.GetComponent<Image>();//tex.pixelInset = new Rect(0, 0, Screen.width, Screen.height);}void Update(){if (sceneStarting){StartScene();}}private void FadeToClear(){tex.color = Color.Lerp(tex.color, Color.clear, fadeSpeed * Time.deltaTime);//以每帧fadeSpeed的速率从当前颜色变清晰}private void FadeToBlack(){tex.color = Color.Lerp(tex.color, Color.black, fadeSpeed * Time.deltaTime);}private void StartScene(){FadeToClear();if (tex.color.a <= 0.05f){tex.color = Color.clear;tex.enabled = false;sceneStarting = false;}}private void EndScene(){tex.enabled = true;FadeToBlack();if (tex.color.a >= 0.95f){SceneManager.LoadScene("Demo");}}

如果觉得《Unity VR学习:第一人称射击游戏(1)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。