- Home /
Saving color to PlayerPrefs
Im trying to save color to PlayerPrefs, but heard that you can easily save color to PlayerPrefsX. Well, the problem I have is that when im trying to use PlayerPrefsX it says that it is unknown identifier. Im using Javascript so can this be a problem here or should I use something else to save the color.
EDIT:
Here is saving:
#pragma strict
var rotatingEnemy : GameObject;
function Update () {
if(Input.GetMouseButtonUp(0)){
var hit : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
var hitObject = hit.collider;
switch(hitObject.name){
case "Background":
break;
default:
PlayerPrefsX.SetColor("enemyColor", hitObject.renderer.material.color);
rotatingEnemy.renderer.material.color = hitObject.renderer.material.color;
break;
}
}
}
Here is loading:
function Start () {
renderer.material.color = PlayerPrefsX.GetColor("enemyColor");
}
Error code:
Assets/scripts/Game/EnemyChangeColor.js(4,35): BCE0005: Unknown identifier: 'PlayerPrefsX'.
and
Assets/scripts/ShopPreviewRotatingEnemyColor.js(16,41): BCE0005: Unknown identifier: 'PlayerPrefsX'.
PlayerPrefsX has two versions. Use the Unityscript version, not C#.
Well, problem solved. Not the first time this kind happens to me, but somehow Unity got bugged and didn't not recognized this file. Went to sleep and after waking up opened up Unity and tried again with no errors. Had same problem with OnClickEvents long time ago, but already forgot restarting fix. Atleast I hopefully remember this next time. :) Thanks for your answers!
Answer by theLucre · Dec 02, 2014 at 04:38 AM
Looks like PlayerPrefsX isn't loaded up correctly. Is the file named PlayerPrefsX.js and class named PlayerPrefsX?
The OP is using Unityscript, so should be using the Unityscript version of PlayerPrefsX.