Error: Assets\Scripts\Guardar.cs(21,16): error CS0029: Cannot implicitly convert type ‘int’ to ‘Health’
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine;
public class Guardar : MonoBehaviour
{
public float PosX;
public float PosY;
public float PosZ;
public Vector3 Posicion;
Health Vida;
private void Awake()
{
Vida = GetComponent<Health>().currenthealth;
}
void Start()
{
CargarDatos();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.F6))
{
GuardarPosicion();
}
if (Input.GetKeyDown(KeyCode.F7))
{
CargarDatos();
}
}
public void GuardarPosicion()
{
PlayerPrefs.SetFloat();
PlayerPrefs.SetFloat("PosicionX", transform.position.x);
PlayerPrefs.SetFloat("PosicionY", transform.position.y);
PlayerPrefs.SetFloat("PosicionZ", transform.position.z);
Debug.Log("Datos Guardados Correctamente");
}
public void CargarDatos()
{
PosX = PlayerPrefs.GetFloat("PosicionX");
PosY = PlayerPrefs.GetFloat("PosicionY");
PosZ = PlayerPrefs.GetFloat("PosicionZ");
Posicion.x = PosX;
Posicion.y = PosY;
Posicion.z = PosZ;
transform.position = Posicion;
Debug.Log("Datos Cargados Correctamente");
}
}
public class Health : MonoBehaviour
{
public int startinghealth = 100;
public int currenthealth;
public Slider healthSlider;
public Image damageImage;
public float flashspeed = 5f;
public Color flashcolor = new Color(1f, 0f, 0f, 0.1f);
public GameObject PersonajeVivo;
public GameObject PersonajeMuerto;
public Animator AnimaiconMuerte;
public GameObject explosion;
public GameObject PantallaEnNegro;
PlayerController player;
PlayerShooting PlayerShooting;
bool isDead;
bool damage;
/* public float TiempoStart = 0;
public float TiempoEnd = 0;
public string Escena;
*/
private void Awake()
{
currenthealth = startinghealth;
PlayerShooting = GetComponent<PlayerShooting>();
player = GetComponent<PlayerController>();
}
void Start()
{
if (damage)
{
damageImage.color = flashcolor;
}
else
{
damageImage.color = Color.Lerp(damageImage.color, Color.clear, flashspeed * Time.deltaTime);
}
damage = false;
PersonajeVivo = GameObject.Find("Personaje 1");
PersonajeMuerto = GameObject.Find("PersonajeAnimacionMuerte");
PersonajeMuerto.SetActive(false);
AnimaiconMuerte.enabled = false;
PantallaEnNegro = GameObject.Find("Image");
PantallaEnNegro.SetActive(false);
}
void Update()
{
}
public void TakeDamage(int amount)
{
damage = true;
currenthealth -= amount;
healthSlider.value = currenthealth;
if (currenthealth <= 0)//&&!isDead)
{
PersonajeVivo.SetActive(false);
PersonajeMuerto.SetActive(true);
player.enabled = false;
AnimaiconMuerte.enabled = true;
Instantiate(explosion, transform.position, transform.rotation);
PantallaEnNegro.SetActive(true);
// Destroy(gameObject, 10f);
// Destroy(gameObject);
/* TiempoStart += Time.deltaTime;
if (TiempoStart >= TiempoEnd)
{
SceneManager.LoadSceneAsync(Escena);
}
*/
}
// void Death()
//{
//isDead = true;
//PlayerShooting.DisableEffects();
// PlayerShooting.enabled = false;
// }
}
}