コード例 #1
0
    public void SetTerrainInfo(TerrainUnitInfo terrainInfo)
    {
        _terrainInfo = terrainInfo;
        info         = terrainInfo;

        health          = info.maxHealth;
        gameObject.name = info.name;
        GetComponent <SpriteRenderer>().sprite = info.unitSprite;

        if (terrainInfo.unitSprites.Length != health && terrainInfo.IsDestructible())
        {
            Debug.LogError(terrainInfo.name + "'s unit sprites are not set up correctly.");
        }
    }
コード例 #2
0
    public void TakeDamage(int damage)
    {
        if (_terrainInfo != null && !_terrainInfo.IsDestructible())
        {
            return;
        }

        if (HasStatus(StatusEffects.FREEZE))
        {
            RemoveStatus(StatusEffects.FREEZE);
            return;
        }

        string audioStr = info.hurtSFX;

        if (audioStr != null && audioStr.Length > 0)
        {
            GameInformation.instance.audio.Play(audioStr);
        }

        health -= damage;

        if (health <= 0)
        {
            health = 0;
        }

        if (_terrainInfo != null)
        {
            GetComponent <TerrainUnit>().ChangeSprite(health, _terrainInfo);
        }

        if (healthbar == null && _terrainInfo != null)
        {
            return;
        }

        healthbar.SetHealth(health, info.maxHealth);

        if (!IsDead())
        {
            GetComponent <Unit>().TakeDamage();
        }
    }