2014-06-14 44 views
0

我寫這段代碼,我不知道如何修復此代碼的所有錯誤,但此代碼在pc模式下正常工作,但在Android模式下給出錯誤這是我的代碼:統一浮動和Android平臺中的對象錯誤

var background : Texture2D; 
var splash : Texture2D; 
var font : Font; 
private var showADPresents = 3.0; 
var size = null; 

static var virtualScreen : Vector2 = Vector2(800, 600); 

function Update() 
{ 
    showADPresents -= Time.deltaTime; 

    if (Application.CanStreamedLevelBeLoaded(1) && Input.anyKeyDown) 
     Application.LoadLevel(1); 
} 

function OnGUI() 
{ 
    GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(Screen.width/virtualScreen.x, Screen.height/virtualScreen.y, 1)); 

    GUI.DrawTexture(Rect(0, 0, virtualScreen.x, virtualScreen.y), splash); 

    if (showADPresents > 0) 
    { 
     var alpha = Mathf.Clamp01(showADPresents); 
     var color = Color.white; 
     color.a = alpha; 
     GUI.color = color; 
     GUI.DrawTexture(Rect(0, 0, virtualScreen.x, virtualScreen.y), background); 

     var presentsStyle = new GUIStyle(GUI.skin.label); 
     presentsStyle.font = font; 
     presentsStyle.fontSize = 48; 
     size = 300; 
     color = Color.black; 
     color.a = alpha; 
     GUI.color = color; 
     GUI.Label(Rect((virtualScreen.x - size) * 0.5, (virtualScreen.y - size) * 0.5, size, size), "Autodesk Presents:", presentsStyle); 
    } 
    else 
    { 
     var notificationStyle = new GUIStyle(GUI.skin.label); 
     notificationStyle.font = font; 
     notificationStyle.fontSize = 16; 
     GUI.color = Color.black; 

     var content = null; 
     if (Application.CanStreamedLevelBeLoaded(1)) 
      content = new GUIContent("Click Screen to Continue"); 
     else 
      content = new GUIContent("Loading..."); 
     size = notificationStyle.CalcSize(content);  
     GUI.Label(Rect((virtualScreen.x - size.x) * 0.5, virtualScreen.y - size.y - 80, size.x, size.y), 
      content, notificationStyle); 
    } 
} 

統一給我這個錯誤,我不能解決這個錯誤plz幫助我的幫助:「(

http://upload.ghashang.com/images/gm214joveg1z354rkli.jpg

PLZ信仰我並不能解決這個錯誤plz幫助我 PLZ解決所有錯誤

回答

0

這是因爲size不是靜態類型。它是動態的,並且因爲從float中減去一個對象沒有操作符,所以會引發此錯誤。你有兩個選擇。一,你可以在減去之前作爲一個浮點數。

GUI.Label(Rect((virtualScreen.x - (float)size) * 0.5, (virtualScreen.y - (float)size) * 0.5, size, size), "Autodesk Presents:", presentsStyle); 

另一種是在聲明中聲明size作爲float或int。

float size = 0.0f; 
//or 
int size = 0; 

但是,以後你嘗試引用size好像它是一個Rect,這會導致其他錯誤。我會a)宣佈sizeRect b)訪問大小的各個成員。您的代碼將是這樣的:

Rect size; 

... 

//remove the size = 300; line and replace it with a constructor 

GUI.Label(Rect((virtualScreen.x - size.x) * 0.5, (virtualScreen.y - size.y) * 0.5, size, size), "Autodesk Presents:", presentsStyle); 

這將解決你的問題,我建議你閱讀更多關於static classes

+0

謝謝你幫助我,當我改變我的代碼統一給我其他錯誤PLZ改變這種代碼爲我plz改變這段代碼的所有行我哪個團結不要給我錯誤plz plz plz幫助我,並改變我的代碼謝謝你的朋友謝謝 – user3288039

+0

@ user3288039嘗試搜索此網站的答案...有很多問題和大多數已經被回答 –

+0

plz更改我的代碼我無法改變只爲我的朋友:'(:* – user3288039