コード例 #1
0
    // Use this for initialization
    void Start()
    {
        if (healthText != null)
        {
            healthText.text = (health / maxHealth * 100).ToString() + "%";
        }
        else
        {
            Debug.LogError("No healthText defined for player: " + gameObject.name);
        }

        if (healthBar != null)
        {
            healthBar.fillAmount = health / maxHealth;
        }
        else
        {
            Debug.LogError("No healthBar Image defined for player: " + gameObject.name);
        }

        invulnScript = GetComponent <PlayerInvulnerability>();
        if (invulnScript == null)
        {
            Debug.LogWarning("No player invulnerability script attached to " + gameObject.name + ". Will not check for it in PlayerHealth. Warning: Player may get frustrated by getting spammed attacked lol");
        }
    }
コード例 #2
0
    public void getHit(int attack)
    {
        PlayerInvulnerability playerInv = player.GetComponent <PlayerInvulnerability> ();

        playerInv.setInvincible(1.0f);

        takeDamage(attack);
    }
コード例 #3
0
    private void Start()
    {
        player = GetComponent <PlayerHealth>();
        if (player == null)
        {
            Debug.LogError("No PlayerHealth found on object: " + gameObject.name + ". Damage from collisions will not be applied.");
        }

        invulnScript = GetComponent <PlayerInvulnerability>();
        if (invulnScript == null)
        {
            Debug.LogWarning("No player invulnerability script attached to " + gameObject.name + ". Will not check for it in PlayerDamage. Warning: Player may get frustrated by getting spammed attacked lol");
        }
    }
コード例 #4
0
    IEnumerator dashRoutine(float direction)
    {
        PlayerInvulnerability playerInv = player.GetComponent <PlayerInvulnerability> ();

        playerInv.setInvincible();

        float time = 0.0f;

        while (time <= 0.15f)
        {
            Vector2 playerPos = playerTransform.localPosition;
            Vector2 dashSpeed = new Vector2(0.5f, 0);

            playerPos.x += dashSpeed.x * direction;
            playerTransform.localPosition = playerPos;
            time += 1.0f * Time.deltaTime;
            yield return(new WaitForSeconds(0.1f * Time.deltaTime));
        }

        playerInv.removeInvincible();

        yield break;
    }