2014-09-25 53 views
0

我設置紋理2是在這樣的PlayerPrefs新的「紋理」:如何用字符串引用紋理?

PlayerPrefs.SetString("texture","texture2") 

但我怎麼可以把下面的腳本的字符串:

PlayerPrefs.GetString("texture") 

到:

mainTexture = PlayerPrefs.GetString("texture") 

所以它會將「紋理2」變成紋理:

mainTexture = texture2 

我沒有使用變量,因爲我想要選擇的紋理被保存(並加載)。提前致謝!任何幫助表示讚賞! :)

回答

0

我已經想通了:

我改變PlayerPrefs到:

PlayerPrefs.SetString("tex","texture2") 

並提出一個更多texture1。

於是,我做了一個叫MuteCheck功能,而這也正是我把裏面的:

public void MuteCheck() 
{ 
    texture = PlayerPrefs.GetString ("tex"); 

    if (texture == "texture2") 
    { 
     textureBool = false; 
    } 
    else if (texture == "texture1") 
    { 
     textureBool = true; 
    } 
} 

,我瘋了經過更新的功能是這樣的:

void Update() 
{ 
    if(textureBool == false) 
    { 
     AudioListener.pause = true; 
     mainTexture = Texture2; 
    } 
    else if(textureBool == true) 
    { 
     AudioListener.pause = false; 
     mainTexture = Texture1; 
    } 
} 

而現在它完美! :)

+0

使用PlayerPrefs.Save()如果你正在爲android做數據保存,如果它是PC沒有需要 – 2014-09-26 08:07:51

+0

因此,而不是PlayerPrefs.SetString,我應該做PlayerPrefs.Save?或者只留下字符串並在其下面添加'PlayerPrefs.Save'? – Bartvb98 2014-09-26 08:18:15

+0

不,在改變場景之前使用PlayerPrefs.Save()不要改變任何東西 – 2014-09-26 08:20:01

0

通過了解其路徑加載紋理是這樣

string texture = "Assets/Resources/abc.png"; 
Texture2D inputTexture = (Texture2D)Resources.LoadAssetAtPath(texture, typeof(Texture2D)); 

,但不是你正在尋找 答案是什麼,根據這些問題thisthis
不轉換串紋理使布爾,如果這是真的如此設置你的紋理tex1如果是假的設置它TEX2

textureBool=Convert.ToBoolean(PlayerPrefs.GetInt("sound")) ; 
if(textureBool)      //when it is true it means it is mute 
    mainTexture=texture2; 
    else         //when it is false it means the speaker is on 
    mainTexture=texture2; 
+0

你好!好的,你已經看過我的腳本了,但是我到底在哪裏添加你的腳本?對不起,我很困惑。順便說一句,謝謝你回答我的所有問題,並幫助我的人! :) – Bartvb98 2014-09-25 17:47:31