2012-12-11 28 views
0

您好我是Unity中的新蜜蜂,我正在開發一個應用程序,在該應用程序中我想要在紋理上以長寬比擬合比例加載圖像。我知道我可以使用ScaleMode.ScaleToFit來實現這一點,但我沒有在Texture 2d中獲得這個屬性。我正在這樣做。如何設置圖像在Unity3d Texture2D上適合的方面

Texture2D tex = Resources.Load("ImageTargetTextures/WhatTheBuck/MYPicture") as Texture2D; 
video.mIconPlane.renderer.material.mainTexture = tex; 
video.mIconPlane.transform.rotation=Quaternion.AngleAxis(180, Vector3.up); 
video.mIconPlane.transform.localScale = ScaleMode.ScaleToFit; 

視頻是我的VideoClass的對象,而mIconPlane是視頻類中的公共遊戲對象。這對我來說很好。提前致謝。

+0

Unity標籤用於Microsoft Unity。請不要濫用它。 –

回答

1

您可以從Texture2D類的公共屬性中獲取圖片的大小像素(可以確切地說明當前的情況)。然後,只需將new Vector3 (textureWidth/someValue, textureHeigth/someValue,1)設置爲video.mIconPlane.transform.localScale即可。 someValue - 是你獲得遊戲對象大小的一些數字。這取決於Camera大小。