Тип 'Player' уже содержит определение для 'Health'

Рейтинг: -3Ответов: 1Опубликовано: 07.02.2023
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour, IDamagble
{
[SerializeField] private int maxHealth;
private int health;
public int Health;

private void Awake()
{
    tag = "Player";
}

public int Health

{
    get 
    { 
        return health; 
    }
    set
    {
        health = value;
        if (health <= 0)
        {
            Die();
            health= 0;
        }
        healthbar.UpdateHealthbar(maxHealth, health);
    }
}
[SerializeField] private Healthbar healthbar;

public void Die()
{
    Destroy(gameObject);
}

[Header("Main Settings")]
[SerializeField] private float attackCooldown;
private bool isCooldown;
[SerializeField] private int attackDamage;

public virtual void Attack()
{
    StartCoroutine(AttackCooldown());
}


public virtual void TakeDamage(int damageValue)
{
    Health -= damageValue;
}


private void Update()
{
    if (isCooldown == false)
    {
        Attack();
    }
}
private IEnumerator AttackCooldown()
{
    isCooldown = true;
    yield return new WaitForSeconds(attackCooldown);
    isCooldown = false;
}
private void Start()
{
    Health = maxHealth;
}

} и 2 скрипт

using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEngine;
using UnityEngine.AI;

public abstract class Enemy : MonoBehaviour, IDamagble
{
[Header("Main Settings")]
[SerializeField] private int health;
public int Health
{
    get { return health;  }
    set 
    { 
        health = value;  
        if (health <= 0)
        {
            Die();
        }
    }
}

public void Die()
{
    Destroy(gameObject);
}

[Header("Main Settings")]
[SerializeField] private float attackCooldown;
private bool isCooldown;
[SerializeField] private int attackDamage;

public virtual void Attack()
{
    StartCoroutine(AttackCooldown());
}


public virtual void TakeDamage(int damageValue)
{
    Health -= damageValue;
}

private void Awake()
{
    tag = "Enemy";
    
    StartCoroutine(AttackCooldown());

}
private void Update()
{
    if (isCooldown == false)
    {
        Attack();
    }
}
private IEnumerator AttackCooldown()
{
    isCooldown = true;
    yield return new WaitForSeconds(attackCooldown);
    isCooldown= false;
}

} Ошибка

Ответы

▲ 1Принят

Прочитайте заголовок своего вопроса. Внимательно прочитайте. А затем обратите внимание на поле и на свойство "Health". Они называются одинаково. Устраните дубль и будет всё хорошо.