Beispiel #1
0
    void Start()
    {
        health = maxHealth;
        text   = FindObjectOfType <PlayerHealthText>();
        text.SetHealthText(health);

        levelManager = FindObjectOfType <LevelManager>();

        spriteRenderer = GetComponentInChildren <SpriteRenderer>();
        audioSource    = GetComponent <AudioSource>();
        shake          = FindObjectOfType <CameraShake>();
    }
Beispiel #2
0
    public void AdjustHitpoints(int delta)
    {
        audioSource.Play();
        shake.Shake();

        health += delta;
        health  = Math.Max(0, health);

        float tint = 0.5f + 0.5f * ((float)health / maxHealth);

        spriteRenderer.color = new Color(1f, tint, tint, 1f);
        if (health <= 0 && levelManager.levelState.Cur == LevelState.State.Playing)
        {
            levelManager.EndLevel(false);
            GetComponent <PlayerInput>().recoilFromHit(4f);
        }
        else if (delta < 0)
        {
            GetComponent <PlayerInput>().recoilFromHit(.5f);
        }
        text.SetHealthText(health);
    }