Unity之黑暗之光按教程学习第二天

          第四步,今天开始昨天中断的项目,控制相机的远近,它的实质Y轴上的变化,从60变化到-20,用到了transform.translate函数控制相机的运动

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovieCamera : MonoBehaviour {

	public float Speed = 10f;

	public float endZ = -20;

	void Start () {
		
	}
	
	void Update () {
		if (transform.position.z < endZ) {
						transform.Translate (Vector3.forward * Speed * Time.deltaTime);
				}
		
	}
}

              我用的是Unity2017版本,所以要给场景添加雾的状态,需要通过window-lighting-setting中,找到Fog选项将其勾选。

             第五步,下面我们要使用到NGUI插件,用白色图片做渐显的效果,NGUI-open-prefabbar ,Create-simppleTexture,我们使用TweenAlpha动画,这个动画中,from,to调整的就是图片的Alpha值,图片透明度,将to 设为0,增加延迟2秒,持续时间3秒,这个可以根据不同电脑的性能自己决定时间。

            第六步,设置开始界面和按钮,有些图片我们需要他在开始不显示,我们可以在ColorTint中将Alph值设为0,加入第五步中用到的动画,如果要图片显示闪烁状,可以将playtype设置为Pingpong,container是同时显示的按键,按钮需要添加Boxcollider和ButtonScript组建。

            第七步,处理按下任何键的事件,它的实质是在父节点找到组建,激活需要的组建,使不需要的组建沉睡。

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PressAnyKey : MonoBehaviour {

	private bool isAnyKeyDown = false;
	private GameObject ButtonContainer;

	void Start () {
				ButtonContainer = this.transform.parent.Find ("ButtonContainer").gameObject;
	}
	
	void Update () {
		if(isAnyKeyDown == false) {
						if (Input.anyKey) {
								ShowButton ();
						}
				}
	}

		private void ShowButton ()
		{
				ButtonContainer.SetActive (true);
				this.gameObject.SetActive (false);
				isAnyKeyDown = true;
		}
}

                 第八步,处理开始按钮和加载按钮,创建OnNewGame和OnloadGame两个类,在按钮上将这两个类添加上

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ButtonContainer : MonoBehaviour {

		public void OnNewGame ()
		{
				PlayerPrefs.SetInt ("DataFromSave", 0);
		}
		public void OnLoadGame ()
		{
				PlayerPrefs.SetInt ("DataFromSave", 1);
		}
}

                     第九步,场景背景声音与按钮点击声音添加,MainCamera使用AudioSoure组建,勾选Loop,调整声音大小,按钮则要添加UI提供的PlaySound脚本。

                    今天就先到这里,休息一下。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李曼竹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值