码迷,mamicode.com
首页 > 其他好文 > 详细

游戏开场镜头拉近场景渐显效果制作

时间:2016-01-09 06:19:21      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:

启动游戏最初的开场会有一个遮罩层的渐变消失,然后镜头拉近到目标场景。镜头拉近主要用 Vector3.MoveTowards() 

1.新建项目,在Hierarchy视图中 Create -> GUITexture项,命名为:WhiteScreen,在Texture中赋值一张白色图片【1024X512.PNG】,具体参数设置如下:

技术分享

2.添加一个EmptyObject(空物体),命名为:TargetPanCamera(相机平移到的目标)放置在最终希望Camera放置的位置。

技术分享

3.新建一个空物体,命名为:ControlScene(控制场景),参数设置如下:

技术分享 

4.将Main Camera 作为ControlScene的子物体,参数设置如下:

技术分享技术分享

5.新建脚本 ControlTirleScene.cs(控制标题场景)【内中还包含了显示隐藏按钮

 ControlTirleScene.cs 代码:

 1 /// <summary>
 2 ///    控制标题场景
 3 ///    这对于控制标题场景的动画脚本的使用(例如,显示/隐藏按钮,相机动画)
 4 /// </summary>
 5 /// 
 6 using UnityEngine;
 7 using System . Collections;
 8 
 9 public class ControlTirleScene : MonoBehaviour
10 {
11     public Transform targetPoint;//摄像要机移动到的那个点
12     //按钮和GUI
13     public GameObject titleText,buttonNew,buttonLoad,whiteScreen;
14 
15     //私有变量
16     private int titlePattern =0;//标题模式
17     private float alpha =0.5f;//透明度
18 
19     void Start()
20     {
21         //设置默认的变量
22         alpha = 0.5f;
23         whiteScreen . SetActive ( true );
24     }
25 
26     void Update()
27     {
28         //相机平移到指定的位置
29         transform . position = Vector3 . MoveTowards ( transform . position , targetPoint . position , 3 * Time . deltaTime );
30 
31         if ( titlePattern==0 )
32         {
33             // 慢慢降低白色遮罩层的透明度
34             if ( alpha >0 )
35             {
36                 alpha -= Time . deltaTime * 0.2f;
37                 whiteScreen . guiTexture . color = new Color ( .5f , .5f , .5f , alpha );
38             }
39 
40             // 当接近目标点的时候,显示游戏title 
41             if ( Mathf . Abs ( transform . position . z - targetPoint . position . z ) <= 6.0f )
42             {
43                 titlePattern = 1;
44                 alpha = 0;
45                 titleText . SetActive ( true );
46             }
47         }
48 
49         if ( titlePattern ==1 )
50         {
51             // 慢慢增加透明度,显示title logo
52             if ( alpha <0.5f )
53             {
54                 alpha += Time . deltaTime * 0.5f;
55                 titleText . guiTexture . color = new Color ( .5f , .5f , .5f , alpha );
56             }
57             else
58             {
59                 titlePattern = 2;
60             }
61         }
62 
63         if ( titlePattern ==2 )
64         {
65             //显示按下启动
66             if ( Input.anyKey  )
67             {
68                 // 处理后续的事
69                 titlePattern = 3;
70             }
71         }
72 
73         if ( titlePattern ==3 )
74         {
75             //显示按钮 新游戏,加载游戏
76             buttonNew . SetActive ( true );
77             buttonLoad . SetActive ( true );
78         }
79     }
80 }

效果图:

技术分享

游戏开场镜头拉近场景渐显效果制作

标签:

原文地址:http://www.cnblogs.com/shakyamuni/p/5115375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!