




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Unity3D實(shí)驗(yàn)六三、實(shí)驗(yàn)內(nèi)容及步驟1. 編寫代碼實(shí)現(xiàn)輕量級(jí)數(shù)據(jù)的存儲(chǔ)和讀取。public class cunchu : MonoBehaviour private string username=""private string passwd=""private string userage=""private string userheight=""private bool showInfo=false;/ Use this for initializationvoid Start () / Update i
2、s called once per framevoid Update () void OnGUI()GUILayout.BeginHorizontal("box",GUILayout.Width(200);GUILayout.Label("請(qǐng)輸入用戶名");username=GUILayout.TextField(username,10);GUILayout.EndHorizontal();GUILayout.BeginHorizontal("box");GUILayout.Label("請(qǐng)輸入密碼");passw
3、d=GUILayout.TextField(passwd,10);GUILayout.EndHorizontal();GUILayout.BeginHorizontal("box");GUILayout.Label("請(qǐng)輸入年齡");userage=GUILayout.TextField(userage,10);GUILayout.EndHorizontal();GUILayout.BeginHorizontal("box");GUILayout.Label("請(qǐng)輸入身高");userheight=GUILayou
4、t.TextField(userheight,5);GUILayout.EndHorizontal();if(GUILayout.Button("提交數(shù)據(jù)")showInfo=true;PlayerPrefs.SetString("username",username);PlayerPrefs.SetString("passwd",passwd);PlayerPrefs.SetInt("userage",int.Parse(userage);PlayerPrefs.SetFloat("userheight
5、",float.Parse(userheight);if(GUILayout.Button("取消查看")showInfo=false;PlayerPrefs.DeleteAll();if(showInfo)GUILayout.Label("輸入的姓名為:"+PlayerPrefs.GetString("username","姓名默認(rèn)值");GUILayout.Label("輸入的密碼為:"+PlayerPrefs.GetString("passwd","
6、密碼默認(rèn)值");GUILayout.Label("輸入的年齡為:"+PlayerPrefs.GetInt("userage",0).ToString();GUILayout.Label("輸入的身高為:"+PlayerPrefs.GetFloat("userheight",0.0f).ToString();2. 編寫代碼實(shí)現(xiàn)自定義文件的存儲(chǔ)和讀取。using UnityEngine;using System.Collections;using System.IO;public class file : M
7、onoBehaviour /string TestInfo="hello !"/ Use this for initializationvoid Start () CreateFile(Application.dataPath,"nnfile","TestInfo");/ Update is called once per framevoid Update () void CreateFile(string path,string name,string Info)StreamWriter sw;FileInfo t=new File
8、Info(path+"/"+name);if(!t.Exists)sw=t.CreateText();elsesw=t.AppendText();sw.WriteLine(Info);sw.Close();sw.Dispose();using UnityEngine;using System.Collections;using System.Collections.Generic;using System.IO;using System;public class file1 : MonoBehaviour / Use this for initializationvoid
9、Start () ArrayList info=LoadFile(Application.dataPath,"nnfile");foreach(string str in info)Debug.Log (str);/ Update is called once per framevoid Update () ArrayList LoadFile(string path,string name)StreamReader str=null;trystr=File.OpenText (path+"/"+name);catch(Exception e)retur
10、n null;string line;ArrayList arr=new ArrayList();while(line=str.ReadLine ()!=null)arr.Add (line);str.Close();str.Dispose ();return arr;3. 編寫代碼實(shí)現(xiàn)鼠標(biāo)拖動(dòng)模型。效果:鼠標(biāo)拖著物體向右走,可以看到物體移動(dòng):源代碼:using UnityEngine;using System.Collections;public class moxingyidong : MonoBehaviour void OnMouseDrag()Debug .Log ("鼠標(biāo)
11、拖動(dòng)模型區(qū)域時(shí)");transform .position +=Vector3 .right*Time.deltaTime*Input .GetAxis ("Mouse X");transform .position +=Vector3 .right*Time.deltaTime*Input .GetAxis ("Mouse Y");/ Use this for initializationvoid Start () / Update is called once per framevoid Update () 實(shí)驗(yàn)7 游戲多媒體三、實(shí)驗(yàn)內(nèi)容及
12、步驟1. 編寫代碼實(shí)現(xiàn)音頻的播放、暫停、停止,和音量等控制方法。using UnityEngine;using System.Collections;public class yinpin : MonoBehaviour public AudioSource music;public float musicVolume;/ Use this for initializationvoid Start () musicVolume =0.5F;void OnGUI()if (GUI.Button(new Rect(10,10,100,50),"播放音樂")if (!music
13、.isPlaying )music.Play ();if (GUI.Button (new Rect(10,60,100,50),"暫停音樂")if(music.isPlaying )music.Stop ();/ Update is called once per framevoid Update () 2. 編寫代碼實(shí)現(xiàn)視頻的播放、暫停、停止等控制方法。源代碼:using UnityEngine;using System.Collections;public class NewBehaviourScript : MonoBehaviour /電影紋理public MovieTexture movTexture;/ Use this for initializationvoid Start () renderer.material.mainTexture = movTexture;movTexture.loop = true;/ Update is called once per framevoid Update
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 頂崗老師班會(huì)課件模板
- 金屬冶煉負(fù)責(zé)人安管人員培訓(xùn)
- 音樂課國防教育課件
- 水肌酸產(chǎn)品項(xiàng)目運(yùn)營管理方案
- 電網(wǎng)側(cè)獨(dú)立儲(chǔ)能示范項(xiàng)目經(jīng)濟(jì)效益和社會(huì)效益分析報(bào)告
- 城鎮(zhèn)污水管網(wǎng)建設(shè)項(xiàng)目人力資源管理方案(模板范文)
- xx片區(qū)城鄉(xiāng)供水一體化項(xiàng)目建設(shè)管理方案
- 先進(jìn)金屬材料行動(dòng)計(jì)劃
- 無人駕駛配送車輛定位精度提升
- 2025年井下多功能測(cè)振儀項(xiàng)目建議書
- 建筑工程文件歸檔管理明細(xì)表
- 如何解讀血常規(guī)報(bào)告
- 區(qū)域消防安全風(fēng)險(xiǎn)評(píng)估規(guī)程DB50-T 1114-2021
- 免疫調(diào)節(jié)治療在腦卒中的運(yùn)用課件
- DB32∕T 186-2015 建筑消防設(shè)施檢測(cè)技術(shù)規(guī)程
- 機(jī)關(guān)檔案管理工作培訓(xùn)PPT課件
- 油輪、化學(xué)品船的基本知識(shí)
- 25T汽車吊檢驗(yàn)報(bào)告
- 變頻空調(diào)中的永磁電機(jī)電感分析
- 高考常考語法填空詞性轉(zhuǎn)換匯總
- AOI自動(dòng)光學(xué)檢測(cè)設(shè)備程序編寫
評(píng)論
0/150
提交評(píng)論