腳本系統
這是Genesis-3D腳本系統的一個實例,使用腳本打印出一行「HelloWorld!」,經過這個例子,用戶能夠知道本身寫的腳本文件是否被運行。同時該log文件時刻記錄着遊戲運行狀況,有幫助用戶調試Bug的做用。html
1.建立工程,命名爲script:併發
![](http://static.javashuo.com/static/loading.gif)
2.在場景中建立一個空物體:編輯器
![](http://static.javashuo.com/static/loading.gif)
3.爲空物體添加腳本組件:ide
![](http://static.javashuo.com/static/loading.gif)
4.在工程目錄欄建立腳本文件helloworld.cs:spa
![](http://static.javashuo.com/static/loading.gif)
咱們會在後面的「腳本調試」入門實例中詳細介紹如何在MonoDevelop裏進行腳本代碼的編寫、編譯和調試,這裏咱們能夠選擇任意的一種代碼編輯器編寫代碼,好比以記事本方式打開。代碼如圖所示:debug
02 |
using System.Runtime.CompilerServices; |
04 |
namespace ScriptRuntime |
06 |
public class helloworld : ScriptableClass |
08 |
public override void OnLoad() |
13 |
public override void OnFrame() |
15 |
Debug.Dbgout( "Hello World!" ); |
5.經過拖拽,將腳本文件掛載到空物件的腳本組件上:3d
![](http://static.javashuo.com/static/loading.gif)
6.保存場景:調試
![](http://static.javashuo.com/static/loading.gif)
7.運行併發布遊戲。點擊"發佈並運行遊戲":code
![](http://static.javashuo.com/static/loading.gif)
出現發佈對話框後,點擊"發佈遊戲":htm
![](http://static.javashuo.com/static/loading.gif)
選擇保存路徑,並將遊戲命名爲script:
![](http://static.javashuo.com/static/loading.gif)
8.稍等一下子,會出現遊戲運行界面。以後關閉運行界面,到…\遊戲發佈\script\logfiles目錄下找到log文件,用UltraEdit打開查看(用戶也能夠用其餘代碼編輯器進行查看):
![](http://static.javashuo.com/static/loading.gif)
能夠看到用戶用腳本系統輸入的文字"Hello World"已經運行。同時該文件時刻記錄遊戲運行狀況,有幫助用戶調試Bug的做用:
![](http://static.javashuo.com/static/loading.gif)
看到這裏,用戶已經知道腳本是如何被編輯器運行的,接下來就開始編寫本身的腳本文件並運行了!