Unity3D實(shí)驗(yàn)六七課件_第1頁
Unity3D實(shí)驗(yàn)六七課件_第2頁
Unity3D實(shí)驗(yàn)六七課件_第3頁
Unity3D實(shí)驗(yàn)六七課件_第4頁
Unity3D實(shí)驗(yàn)六七課件_第5頁
已閱讀5頁,還剩5頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論