public Transform Sun;
public Transform Sky;
public SpriteRenderer sprite;
private float distantion;
void Update()
{
var color = sprite.color;
distantion = Vector3.Distance(Sun.position, Sky.position);
int a = 100;
for (int i = 0; i < 100; i++)
{
a--;
float[] alfa = new float[100];
alfa[i] = a * 0.01f;
float[] _distantion = new float[100];
_distantion[i] = 163 - i * 1.63f;
if (distantion <= _distantion[i] && distantion > _distantion[i] - 1.63f)
{
color.a = alfa[i];
sprite.color = color;
}
}
}
public class Player : Monobehaviour
public void Start()
{
SavePlayer();
LoadPlayer();
}
[Header("Player Info Parameters")]
[Range(0, 250)] public int health = 100;
[Range(0, 9999)] public int money = 0;
[Range(0, 150)] public int level = 0;
[Range(0, 150)] public int levelSpeedBust = 0;
[Range(0, 150)] public int levelStrongBust = 0;
[Range(0, 150)] public int levelHealthBust = 0;
public int maxHealth = 100;
public void SavePlayer()
{
SaveSystem.SavePlayer(this);
}
public void LoadPlayer()
{
GameData data = SaveSystem.LoadPlayer();
health = data.health;
money = data.money;
level = data.level;
maxHealth = data.maxHealth;
levelSpeedBust = data.levelSpeedBust;
levelStrongBust = data.levelStrongBust;
levelHealthBust = data.levelHealthBust;
Vector3 position;
position.x = data.position[0];
position.y = data.position[1];
position.z = data.position[2];
transform.position = position;
}
public class SaveSystem
{
public static void SavePlayer(Player player)
{
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + "/player.save";
FileStream stream = new FileStream(path, FileMode.Create);
GameData data = new GameData(player);
formatter.Serialize(stream, data);
stream.Close();
}
public static GameData LoadPlayer()
{
string path = Application.persistentDataPath + "/player.save";
if (File.Exists(path))
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
GameData data = formatter.Deserialize(stream) as GameData;
stream.Close();
return data;
}
else
{
Debug.LogError("Save file not found in" + path);
return null;
}
}
}
[System.Serializable]
public class GameData
{
public bool autoSave;
public int health;
public int money;
public int maxHealth;
public int level;
public int levelSpeedBust;
public int levelStrongBust;
public int levelHealthBust;
public float[] position;
public GameData(Player player)
{
health = player.health;
money = player.money;
maxHealth = player.maxHealth;
level = player.level;
levelSpeedBust = player.levelSpeedBust;
levelStrongBust = player.levelStrongBust;
levelHealthBust = player.levelHealthBust;
position = new float[3];
position[0] = player.transform.position.x;
position[1] = player.transform.position.y;
position[2] = player.transform.position.z;
}
}