Beispiel #1
0
 void OnCollisionEnter2D(Collision2D other)
 { //causa dano ao acertar, com chance de critico
     if (other.gameObject.CompareTag("Enemy"))
     {
         if (Random.value <= Player.GetComponent <PlayerController>().CritChance)
         {
             other.gameObject.GetComponentInChildren <HealthBar>().TakeDamage(Player.GetComponent <PlayerController>().BowDamage *Player.GetComponent <PlayerController>().CritMult, true);
         }
         else
         {
             other.gameObject.GetComponentInChildren <HealthBar>().TakeDamage(Player.GetComponent <PlayerController>().BowDamage, false);
         }
         Destroy(gameObject);
     }
     if (other.gameObject.CompareTag("Player"))
     {
         if (Enemy.GetComponent <EnemyController>() != null)
         {
             if (Random.value <= Enemy.GetComponent <EnemyController>().CritChance)
             {
                 PlayerHealthBar.TakeDamage(Enemy.GetComponent <EnemyController>().BowDamage *Enemy.GetComponent <EnemyController>().CritMult, true);
             }
             else
             {
                 PlayerHealthBar.TakeDamage(Enemy.GetComponent <EnemyController>().BowDamage, false);
             }
         }
     }
     Destroy(gameObject);
 }
Beispiel #2
0
        private void PlayerTakeDamage(Collision collision)
        {
            if (collision.gameObject.GetComponent <DamageOnCollision>() != null)
            {
                var collisionType   = collision.gameObject.GetComponent <DamageOnCollision>().damageImpact;
                var collisionDamage = player.GetDamageValues(collisionType);

                player.TakeDamage(collisionDamage);
                var currentHealth = player.GetCurrentHealth(trackHealth);

                if (currentHealth > Mathf.Epsilon)
                {
                    state = State.Alive;
                    audioSource.PlayOneShot(damageImpact);

                    // On collision with any object, make sure player is still facing front (left to right)
                    // and lock the Z-axis, so they are still moving along the gamepath
                    astronaut.transform.eulerAngles = new Vector3(0, 0, 0);
                    astronaut.transform.position    = new Vector3(transform.position.x, transform.position.y, 0);
                }
                else
                {
                    state = State.Dying;
                    audioSource.Stop();
                    audioSource.PlayOneShot(death);
                    deathParticles.Play();
                    Invoke("LoadFirstLevel", levelLoadDelay);
                }
            }
        }
    // when the collsion of the two players happens
    //void OnCollisionStay(Collision collisionInfo)
    //{
    //    if (collisionInfo.gameObject.tag =="Player")
    //    {
    //        if(Attack())
    //            collisionInfo.collider.SendMessageUpwards("PlayerDamage",damage,SendMessageOptions)
    //    }
    //}

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            anim.SetBool("isAttacking", true);
            PlayerHealthBar ph = other.GetComponent <PlayerHealthBar>();

            if (ph != null)
            {
                ph.TakeDamage(damagePlayer);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (controller != null)
        {
            controller.Move();
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            CameraShake.ins.CoShake(0.5f, 0.2f);
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            healthBar.TakeDamage(10f);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            healthBar.TakeDamage(-10f);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            CameraTargetFocus.ins.InvokeFocuse(target, false);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            CameraTargetFocus.ins.InvokeFocuse(transform, true);
        }
        else if (Input.GetKeyDown(KeyCode.Space) && Time.time > attackTime)
        {
            attackTime = Time.time + Constant.ATTACK_TIME;
            SoundManager.ins.Play(audioAttack);

            //해방향으로 파티클 생성... 시간되면 자동 소멸...
            int            _idx      = controller.GetDir();
            ParticleSystem _particle = Instantiate(prefabSkillEffect, listPoints[_idx].position, Quaternion.identity) as ParticleSystem;
            Destroy(_particle.gameObject, _particle.main.duration);
        }
    }