Unity 3D 计算机游戏设计实验指导书七文档格式.docx

上传人:b****5 文档编号:18972673 上传时间:2023-01-02 格式:DOCX 页数:11 大小:1.46MB
下载 相关 举报
Unity 3D 计算机游戏设计实验指导书七文档格式.docx_第1页
第1页 / 共11页
Unity 3D 计算机游戏设计实验指导书七文档格式.docx_第2页
第2页 / 共11页
Unity 3D 计算机游戏设计实验指导书七文档格式.docx_第3页
第3页 / 共11页
Unity 3D 计算机游戏设计实验指导书七文档格式.docx_第4页
第4页 / 共11页
Unity 3D 计算机游戏设计实验指导书七文档格式.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

Unity 3D 计算机游戏设计实验指导书七文档格式.docx

《Unity 3D 计算机游戏设计实验指导书七文档格式.docx》由会员分享,可在线阅读,更多相关《Unity 3D 计算机游戏设计实验指导书七文档格式.docx(11页珍藏版)》请在冰豆网上搜索。

Unity 3D 计算机游戏设计实验指导书七文档格式.docx

}

//Updateiscalledonceperframe

voidUpdate(){

voidOnGUI()

{

GUILayout.BeginHorizontal("

box"

GUILayout.Width(200));

GUILayout.Label("

请输入用户名"

);

username=GUILayout.TextField(username,10);

GUILayout.EndHorizontal();

请输入密码"

passwd=GUILayout.TextField(passwd,10);

请输入年龄"

userage=GUILayout.TextField(userage,10);

请输入身高"

userheight=GUILayout.TextField(userheight,5);

if(GUILayout.Button("

提交数据"

))

{

showInfo=true;

PlayerPrefs.SetString("

username"

username);

passwd"

passwd);

PlayerPrefs.SetInt("

userage"

int.Parse(userage));

PlayerPrefs.SetFloat("

userheight"

float.Parse(userheight));

}

取消查看"

showInfo=false;

PlayerPrefs.DeleteAll();

if(showInfo)

GUILayout.Label("

输入的姓名为:

+PlayerPrefs.GetString("

"

姓名默认值"

));

输入的密码为:

密码默认值"

输入的年龄为:

+PlayerPrefs.GetInt("

0).ToString());

输入的身高为:

+PlayerPrefs.GetFloat("

0.0f).ToString());

}

2.编写代码实现自定义文件的存储和读取。

usingUnityEngine;

usingSystem.Collections;

usingSystem.IO;

publicclassfile:

//stringTestInfo="

hello!

CreateFile(Application.dataPath,"

nnfile"

TestInfo"

voidCreateFile(stringpath,stringname,stringInfo){

StreamWritersw;

FileInfot=newFileInfo(path+"

//"

+name);

if(!

t.Exists){

sw=t.CreateText();

else{

sw=t.AppendText();

sw.WriteLine(Info);

sw.Close();

sw.Dispose();

usingSystem.Collections.Generic;

usingSystem;

publicclassfile1:

ArrayListinfo=LoadFile(Application.dataPath,"

foreach(stringstrininfo){

Debug.Log(str);

ArrayListLoadFile(stringpath,stringname){

StreamReaderstr=null;

try{

str=File.OpenText(path+"

}catch(Exceptione){

returnnull;

stringline;

ArrayListarr=newArrayList();

while((line=str.ReadLine())!

=null){

arr.Add(line);

str.Close();

str.Dispose();

returnarr;

3.编写代码实现鼠标拖动模型。

效果:

鼠标拖着物体向右走,可以看到物体移动:

源代码:

publicclassmoxingyidong:

voidOnMouseDrag()

Debug.Log("

鼠标拖动模型区域时"

transform.position+=Vector3.right*Time.deltaTime*Input.GetAxis("

MouseX"

MouseY"

实验7游戏多媒体

1.编写代码实现音频的播放、暂停、停止,和音量等控制方法。

publicclassyinpin:

publicAudioSourcemusic;

publicfloatmusicVolume;

musicVolume=0.5F;

if(GUI.Button(newRect(10,10,100,50),"

播放音乐"

if(!

music.isPlaying)

{

music.Play();

}

if(GUI.Button(newRect(10,60,100,50),"

暂停音乐"

if(music.isPlaying)

music.Stop();

2.编写代码实现视频的播放、暂停、停止等控制方法。

publicclassNewBehaviourScript:

//电影纹理

publicMovieTexturemovTexture;

renderer.material.mainTexture=movTexture;

movTexture.loop=true;

voidOnGUI(){

if(GUILayout.Button("

播放/继续"

)){

if(!

movTexture.isPlaying){

movTexture.Play();

暂停播放"

movTexture.Pause();

停止播放"

movTexture.Stop();

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 材料科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1