实验目的:
进一步了解Unity3D引擎
实验要求:
完成一些特效的实现
实验环境:
PC机,Unity3D软件
实验内容:
-
一、给人物添加光粒
二、给篝火添加火焰特效
1.导入火焰图片
2.使用导入的火焰图片创建材质球
(1)选择Create->Material
(2)对材质球做一点更改
(3)给篝火添加粒子特效
(4)将火焰材质球导入
三、设置游戏关卡
1.将所使用的图形界面导入到Assets文件下,并将当前项目保存为main.unity
2.创建代码脚本keyboardback.cs,并添加到Main Camera中
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class keyboardback : MonoBehaviour
{
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.F1))
{
SceneManager.LoadScene("help");
//Application.LoadLevel("help");
}
if (Input.GetKeyDown(KeyCode.F2))
{
SceneManager.LoadScene("menu");
//Application.LoadLevel("menu");
}
}
}
3.建立新场景,并新建代码脚本文件help.cs并添加至Main Camera
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class help : MonoBehaviour
{
public Texture2D helppic;
void OnGUI()
{
GUI.DrawTexture(new Rect(0, 0, Screen.width,
Screen.height), helppic, ScaleMode.StretchToFill);
if (GUI.Button(new Rect(Screen.width - 880, Screen.height - 90, 240, 80), "返回游戏"))
{
SceneManager.LoadScene("main");
}
//返回主菜单
if (GUI.Button(new Rect(Screen.width - 1280, Screen.height - 90, 240, 80), "返回菜单"))
{
SceneManager.LoadScene("menu");
}
}
}
4.将help.jpg拖到右边Inspector的Helppic中
5.保存当前场景为help.unity,在 Build Setting 中添加关卡 help.unity
6.建立新场景,并新建代码脚本文件Menu.cs并添加至Main Camera
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Menu: MonoBehaviour
{
public Texture2D mainMenuBG;
void OnGUI()
{
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), mainMenuBG, ScaleMode.StretchToFill);
if (GUI.Button(new Rect(Screen.width - 1080, Screen.height - 380, 240, 80), "开始游戏"))
{
SceneManager.LoadScene("main");
}
if (GUI.Button(new Rect(Screen.width - 1080, Screen.height - 180, 240, 80), "退出游戏"))
{
Application.Quit();
}
if (GUI.Button(new Rect(Screen.width - 1080, Screen.height - 280, 240, 80), "帮助"))
{
SceneManager.LoadScene("help");
}
}
}