예제 #1
0
    //private void Update()
    //{
    //    if (Input.GetKeyDown(KeyCode.K) && isLocalPlayer)
    //        TakeDamage(30, "Magic");
    //    if (Input.GetKeyDown(KeyCode.V) && isLocalPlayer)
    //        Win();
    //    if (Input.GetKeyDown(KeyCode.C) && isLocalPlayer)
    //        ratio = "Shit :(";
    //}

    public void TakeDamage(int damage, string type)
    {
        if (isDead)
        {
            return;
        }
        if (type == "Magic")
        {
            camShake.ShakeCam(fireBallShakePosMag, fireBallShakeRotMag);
        }
        else
        {
            camShake.ShakeCam(shakeDelay);
        }


        if (type == "Sword")
        {
            //blood particle
            audioManager.PlaySFX("Sword Hit");
            GameObject particle = Instantiate(swordHitParticle, hitHolder);
            Destroy(particle, 1f);
        }
        else if (type == "Fist")
        {
            //hit effect
            audioManager.PlaySFX("Fist Hit");
            GameObject particle = Instantiate(fistHitParticle, hitHolder);
            Destroy(particle, 1f);
        }

        audioManager.PlaySFX("Pain");

        currentHealth -= damage;
        if (currentHealth < 0)
        {
            currentHealth = 0;
        }
        SetHealthBar(currentHealth);

        if (isLocalPlayer)
        {
            if (currentHealth == 0)
            {
                Die();
            }
            animator.SetInteger("HitNO", Random.Range(1, 4));
            animator.SetTrigger("GotHit");
        }
        if (currentHealth == 0 && !isLocalPlayer)
        {
            manager.localPlayer.GetComponent <Player>().Win();
        }
    }
예제 #2
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Environment"))
     {
         Collider2D[] objectsToDamage = Physics2D.OverlapCircleAll(transform.position, areaOfEffect, whatIsDestructible);
         for (int i = 0; i < objectsToDamage.Length; i++)
         {
             objectsToDamage[i].GetComponent <DestructibleEnvi>().health -= damage;
             shake.ShakeCam();
         }
         GameObject terEffect = Instantiate(effect, transform.position, Quaternion.identity);
         Destroy(gameObject);
         Destroy(terEffect, 0.5f);
     }
 }
예제 #3
0
 void Update()
 {
     if (timer <= 0)
     {
         Collider2D[] objectsToDamage = Physics2D.OverlapCircleAll(transform.position, areaOfEffect, whatIsDestructible);
         for (int i = 0; i < objectsToDamage.Length; i++)
         {
             objectsToDamage[i].GetComponent <DestructibleEnvi>().health -= damage;
             shake.ShakeCam();
         }
         GameObject effectD = Instantiate(bombEffect, transform.position, Quaternion.identity);
         Destroy(gameObject);
         Destroy(effectD, 1f);
     }
     else
     {
         timer -= Time.deltaTime;
     }
 }
예제 #4
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.transform.root.name == transform.root.name)
        {
            return;
        }

        GetComponent <Rigidbody>().velocity = Vector3.zero;
        GameObject tempExplosion = Instantiate(explosion, transform.position, Quaternion.identity);

        Destroy(this.gameObject, destroyDelay);

        if (other.tag != "Player")
        {
            camShake.ShakeCam(explosionShakeMag, explosionRotMag);
            return;
        }

        if (transform.root.name == "local player")
        {
            actionControl.Damage(other.GetComponent <NetworkIdentity>().netId.ToString(), damage, "Magic");
        }
    }