變數在不同區域(scope)的優先權

views

public myInt = 3; 

Start()
{
    myInt = 11; 
    print(myInt);
}
									

由上例,最後myInt為11

另外如果沒有在Start( )做初始化/指定數值,而且myInt又是宣告成public的情形下,那會以Inspector的數值為優先

結論:

A: 在宣告區

B: 在Start( )

C: 在Inspector (在runtime之前/在遊戲開始之前)

優先權 B > C > A

This entry was posted in 遊戲文章 by Mr.M. Bookmark the permalink.


Leave a Reply

Your email address will not be published. Required fields are marked *