示例#1
0
    private void FirePellet(LineRenderer traceLine)
    {
        int        targetable = LayerMask.GetMask("Enemy");
        Ray        weaponRay  = new Ray();
        RaycastHit hit;
        Vector3    impactPoint;

        ConstructWeaponRay(ref weaponRay);

        if (Physics.Raycast(weaponRay, out hit, range, targetable))
        {
            impactPoint = hit.point;
            EnemyHealth unit = hit.collider.GetComponent <EnemyHealth>();

            if (unit)
            {
                unit.Damage(damage, knockbackForce, hit);
            }
        }
        else
        {
            impactPoint = weaponRay.origin + weaponRay.direction * range;
        }

        ApplyForceAlongRaycast(weaponRay);

        traceLine.SetPosition(0, muzzle.transform.position);
        traceLine.SetPosition(1, impactPoint);
        traceLine.enabled = true;
    }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKey(KeyCode.Mouse0) && Time.time > nextFire)
     {
         nextFire = Time.time + fireRate;
         Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
         RaycastHit hit;
         laserLine.SetPosition(0, gunEnd.position);
         if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
         {
             laserLine.SetPosition(1, hit.point);
             if (hit.collider.tag == "Enemy")
             {
                 anim.SetTrigger("knifeStab");
                 health = hit.collider.GetComponent <EnemyHealth>();
                 if (health != null)
                 {
                     health.Damage(gunDamage);
                 }
                 if (hit.rigidbody != null)
                 {
                     hit.rigidbody.AddForce(-hit.normal * hitForce);
                 }
             }
         }
         else
         {
             laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
             anim.SetTrigger("knifeStabMiss");
         }
     }
 }
示例#3
0
    private void Laser()
    {
        if (!lineRender.enabled)
        {
            lineRender.enabled = true;
            impactEffect.Play();
            pointLight.enabled = true;
        }

        // Damage enemy
        _enemyHp.Damage(overTimeDmg * Time.deltaTime, EnemyHealth.DamageType.Laser);

        // Slow Enemy
        //_enemyMove.Slow(slowPct);

        // Draw the laser line
        var bulletPosition = _bulletPoint.position;
        var targetPosition = target.position;

        targetPosition.y += 1;
        lineRender.SetPosition(0, bulletPosition);
        lineRender.SetPosition(1, targetPosition);

        // Change Effect position and rotation
        var dir = bulletPosition - targetPosition;

        impactEffect.transform.transform.position = targetPosition + dir.normalized * 1;
        impactEffect.transform.rotation           = Quaternion.LookRotation(dir.normalized);
    }
示例#4
0
    // 주인공 캐릭터가 일반 공격을 할 때 호출됩니다.
    // 메카님 작동 방식을 업그레이드 하면서 공격이 처리되는 순서가 변경됩니다.
    public void NormalAttack()
    {
        // 일반 공격을 할 때 재생될 수 있는 주인공 캐릭터의 목소리들입니다.
        // 이 목소리들 중 하나가 랜덤으로 재생됩니다.
        string[] attackSound = { "VoiceSample/13.attack_B1",
                                 "VoiceSample/13.attack_B1","VoiceSample/14.attack_B2",
                                 "VoiceSample/15.attack_B3","VoiceSample/16.attack_C1",
                                 "VoiceSample/17.attack_C2","VoiceSample/18.attack_C3" };

        // 목소리 리스트 중에서 하나를 랜덤으로 재생시키는 함수입니다.
        PlayRandomVoice(attackSound);

        // normalTarget에 붙어있는 Trigger Collider에 들어있는 몬스터의 리스트를 조회합니다.
        List <Collider> targetList
            = new List <Collider>(normalTarget.targetList);

        // 타겟 리스트 안에 있는 몬스터들을 foreach 문으로 하나하나 다 조회합니다.
        foreach (Collider one in targetList)
        {
            // 타겟의 게임 오브젝트에 EnemyHealth라는 스크립트를 가져옵니다.
            EnemyHealth enemy = one.GetComponent <EnemyHealth>();
            // 만약 EnemyHealth 스크립트가 있다면 몬스터이므로, 몬스터에게 데미지를 줍시다.
            if (enemy != null)
            {
                // 몬스터에게 데미지를 주면서, 데미지를 얼마 줄지, 얼마나 뒤로 밀려날지(pushBack),
                // 타격 이펙트는 뭘 줄지(effectPrefab), 오디오는 뭘 재생할지(audio)를 매개변수로 전달합니다.
                enemy.Damage(NormalDamage, transform.position, 2f,
                             "SkillAttack1", "Audio/explosion_enemy");
            }
        }
    }
示例#5
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.J))
     {
         enemy.Damage(-damage);
     }
 }
示例#6
0
    void OnTriggerEnter(Collider other)
    {
        AudioSource.PlayClipAtPoint(hitSound, other.transform.position, 1f);
        EnemyHealth health = other.GetComponent <EnemyHealth>();

        if (health != null)
        {
            health.Damage(bulletDamage);
        }
        if (other.GetComponent <Rigidbody>() != null)
        {
            other.GetComponent <Rigidbody>().AddForce(transform.forward * hitForce);
        }

        if (other.gameObject.CompareTag("FloorTile"))
        {
            Renderer rend = other.gameObject.GetComponent <Renderer>();
            sb.UpdateCounts(rend.sharedMaterial, bulletMaterial);
            rend.material = bulletMaterial;
        }

        //m_ExplosionParticles.transform.parent = null;
        //m_ExplosionParticles.Play();


        Destroy(gameObject);
    }
示例#7
0
    void Update()
    {
        anim = GetComponent <Animator> ();

        colliding = Physics2D.Linecast(sightStart1.position, sightEnd1.position);

        if (grounded && Input.GetKeyDown(KeyCode.UpArrow))
        {
            anim.SetBool("Ground", false);
            GetComponent <Rigidbody2D>().AddForce(new Vector2(0, jumpForce));
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            PlaySound(0);
            anim.SetTrigger("Punch");
            {
                if (colliding)
                {
                    enemyHealth = GetComponent <EnemyHealth>();

                    if (enemyHealth != null)
                    {
                        enemyHealth.Damage(damagePerHit);
                    }
                }
            }

            GetComponent <Animation>().wrapMode = WrapMode.Once;
        }
    }
    public void Fire()
    {
        DeductAmmo();
        int targetable = LayerMask.GetMask("Enemy");

        Ray        weaponRay = new Ray();
        RaycastHit hit;
        Vector3    impactPoint;

        ConstructWeaponRay(ref weaponRay);

        if (Physics.Raycast(weaponRay, out hit, range, targetable))
        {
            impactPoint = hit.point;
            EnemyHealth unit = hit.collider.GetComponent <EnemyHealth>();

            if (unit)
            {
                unit.Damage(damage, knockbackForce, hit);
            }
        }
        else
        {
            impactPoint = weaponRay.origin + weaponRay.direction * range;
        }

        ApplyForceAlongRaycast(weaponRay);

        traceLine.SetPosition(1, impactPoint);
        traceLine.enabled = true;

        Invoke("DisableTraceLine", traceTime);
        AddCameraTrauma(trauma);
    }
示例#9
0
    public void SkillAttack()
    {
        List <Collider> listTargets = m_skillTarget.m_listTargets;

        foreach (Collider collider in listTargets)
        {
            EnemyHealth enemyHealth = collider.GetComponent <EnemyHealth>();

            if (enemyHealth != null)
            {
                enemyHealth.Damage
                (
                    m_nSkillDamage,
                    transform.position,
                    10.0f,
                    E_SKILL_TYPE.E_SKILL_01,
                    "Audio/explosion_player"
                );
            }
            else
            {
                Debug.Log("Enemy_Health_Missing..");
            }
        }
    }
示例#10
0
    private void EnemyDamage(Transform enemy, float damage)
    {
        EnemyHealth enemyHP = enemy.GetComponent <EnemyHealth>();

        if (enemyHP != null)
        {
            enemyHP.Damage(damage);
        }
    }
示例#11
0
    private void EnemyDamage()
    {
        EnemyHealth enemyHp = target.GetComponent <EnemyHealth>();

        if (enemyHp != null)
        {
            enemyHp.Damage(damage);
        }
    }
    public void DamageEnemy(float damage)
    {
        // Damage enemy - caused by player shooting
        health.Damage(damage);

        health.ShowUI();

        AlertEnemy();
    }
示例#13
0
    // TYÖN ALLA!!!!!
    void LightningLine(float lightningWeaponRange)
    {
        float lightningGunDamage = 12.5f;
        float lightningFireRate  = .2f;
        //float lightningWeaponRange = 15f;
        float lightningHitForce = 50f;

        float time = 0;

        RaycastHit hit;

        //Set position to the center of the screen using ViewPortToWorldPoint.
        Vector3 rayOrigin = FpsCam.ViewportToWorldPoint(new Vector3(.5f, .5f, 0f));

        //if (Input.GetMouseButtonDown (0) && Time.time > NextFire)
        //{
        //	//time += Time.deltaTime;

        //	NextFire = Time.time + lightningFireRate;
        //	StartCoroutine (SingleTapShotEffect ());

        LaserLine.SetPosition(0, LightningEffect.transform.position);

        /*if (Input.GetMouseButtonUp (0) && time < 3)
         * {
         *
         * }
         * else if (Input.GetMouseButtonUp (0) && time >= 3) {
         *  StartCoroutine (ThreeSecondHoldShotEffect ());
         * }
         * else if (Input.GetMouseButtonUp (0) && time >= 5)
         * {
         *  StartCoroutine (FiveSecHoldShotEffect ());
         * }
         */

        if (Physics.Raycast(rayOrigin, FpsCam.transform.forward, out hit, lightningWeaponRange))
        {
            LaserLine.SetPosition(1, hit.point);

            EnemyHealth health = hit.collider.GetComponentInParent <EnemyHealth>();

            if (health != null)
            {
                health.Damage(lightningGunDamage);
                Debug.Log(health.BruteHealth);
            }
        }
        else
        {
            LaserLine.SetPosition(1, rayOrigin + (FpsCam.transform.forward * lightningWeaponRange));
        }

        //time = 0;
        //}
    }
示例#14
0
    private void EnemyDamage()
    {
        EnemyHealth enemyHp = mTarget.GetComponent <EnemyHealth>();

        if (enemyHp != null && enemyHp.isAlive())//增加了isAlive(),因为现在enemy在空血时依旧可能存在
        {
            Debug.Log("扣血了");
            enemyHp.Damage(damageNum);
        }
    }
示例#15
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log(collision.gameObject.tag);
        EnemyHealth enemyHealth = collision.gameObject.GetComponent <EnemyHealth>();

        if (enemyHealth != null)
        {
            enemyHealth.Damage(bulletDamage);
        }
        Destroy(gameObject);
    }
示例#16
0
    void HitTarget()
    {
        GameObject effectIns = (GameObject)Instantiate(bullectHitEffect, transform.position, transform.rotation);

        Destroy(effectIns, 2f * GameSpeed.speed);

        health.Damage(damage);

        Destroy(gameObject);
        return;
    }
示例#17
0
 private void OnTriggerEnter(Collider other)
 {
     //print("Light Triggered");
     if (GetComponent <SphereCollider>().bounds.Contains(other.gameObject.transform.position))
     {
         if (other.gameObject.tag == "Enemy")
         {
             EnemyHealth health = other.gameObject.GetComponent <EnemyHealth>();
             health.Damage(9999f);
         }
     }
 }
示例#18
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("Enemy"))
     {
         EnemyHealth health = collision.gameObject.GetComponent <EnemyHealth>();
         if (health != null)
         {
             health.Damage(bulletDamage);
         }
     }
     Destroy(gameObject);
 }
示例#19
0
 private void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.tag == "Bullet")
     {
         health.Damage(damage_dealt);
         EnemyLogic();
         if (health.enemyHealth <= 0.0f)
         {
             AudioSource.PlayClipAtPoint(death, transform.position);
             agent.speed = 0f;
         }
     }
 }
 void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         PlayerOuch.Play();
         _playerhealth.Damage(20);
     }
     if (other.CompareTag("Projectile"))
     {
         ZombieOuch.Play();
         _enemyhealth.Damage(10);
     }
 }
示例#21
0
 private void OnTriggerStay(Collider other)
 {
     if (other.gameObject.CompareTag("Enemy"))
     {
         if (other.gameObject.GetComponent <CapsuleCollider>().bounds.Contains(transform.position))
         {
             EnemyHealth health = other.gameObject.GetComponent <EnemyHealth>();
             if (health != null)
             {
                 health.Damage(bulletDamage);
             }
         }
     }
 }
示例#22
0
    private void CollideWithEnemy(Collision col)
    {
        if (col.transform.CompareTag("Target"))
        {
            EnemyHealth eh = col.transform.GetComponent <EnemyHealth>();
            if (eh != null)
            {
                eh.Damage(dmg);

                if (eh.curHP <= 0)
                {
                    ProjectileWhoShoot who = transform.GetComponent <ProjectileWhoShoot>();
                    PlayerScore        ps  = who.who.GetComponent <PlayerScore>();
                    ps.AddScore(100);
                }
            }
        }
    }
示例#23
0
    private void HandleDamageEnemy(int id, int damage)
    {
        GameObject gameObject;

        networkedObjects.TryGetValue(id, out gameObject);
        //ALTER HEALTH OF ENEMY MAN
        EnemyHealth eh = gameObject.GetComponent <EnemyHealth>();

        if (eh != null)
        {
            //just use damage, that's fine
            eh.Damage(damage);
        }
        else
        {
            Debug.LogError("Couldn't find enemy health tracking from network id" + id);
        }
    }
示例#24
0
    void OnTargetHit(EnemyHealth target, Vector3 location)
    {
        Debug.Log("Hit " + target + " with sword!");
        EnemyMovement movement = target.GetComponent <EnemyMovement>();
        float         damage   = (movement.IsPlayerBehind()) ? 999f: strikeDamage;

        target.Damage(damage, 0);
        target.hitContainer.active             = true;
        target.hitContainer.transform.position = location;
        //calculate correct rotation so that the player can see the label right
        float rotation = (movement.IsPlayerBehind()) ? 0f : 180f;

        target.hitContainer.transform.localRotation = Quaternion.identity;
        target.hitContainer.transform.Rotate(new Vector3(0f, rotation, 0f));

        target.hitMesh.text = "+ " + damage;
        StartCoroutine(HideHitMessage(target));
    }
示例#25
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKey(KeyCode.Mouse0) && Time.time > nextFire && ammo > 0)
     {
         ammo--;
         ammoAmount.text = ammo.ToString();
         anim.SetTrigger("gunShoot");
         nextFire = Time.time + fireRate;
         StartCoroutine(ShotEffect());
         Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
         RaycastHit hit;
         laserLine.SetPosition(0, gunEnd.position);
         if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
         {
             laserLine.SetPosition(1, hit.point);
             if (hit.collider.tag == "Enemy")
             {
                 health = hit.collider.GetComponent <EnemyHealth>();
                 if (health != null)
                 {
                     health.Damage(gunDamage);
                 }
             }
             else if (hit.collider.tag == "Boss")
             {
                 boss = hit.collider.GetComponent <BossController>();
                 if (boss != null)
                 {
                     boss.Damage(gunDamage);
                 }
                 if (hit.rigidbody != null)
                 {
                     hit.rigidbody.AddForce(-hit.normal * hitForce);
                 }
             }
         }
         else
         {
             laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
         }
     }
 }
    private void CreateWeapon()
    {
        if (waitTurns > 0)
        {
            waitTurns--;
            return;
        }
        Vector2           searchPosition = PlayerMovement.TargetPosition + PlayerMovement.FacingDirection;
        EnemyBaseMovement e = EnemyBaseMovement.GetEnemy(searchPosition);

        if (e != null)
        {
            EnemyHealth health = e.GetComponent <EnemyHealth>();
            if (health != null)
            {
                health.Damage(Random.Range(10, 25));
                waitTurns += 1;
            }
        }
    }
示例#27
0
    IEnumerator DOTCoroutine(float duration, int damage)
    {
        dotted = true;

        // Particle effect
        var main = particle.main;

        main.startColor = new ParticleSystem.MinMaxGradient(Color.red, Color.yellow);
        particle.Play();

        while (duration > 0)
        {
            health.Damage(damage);
            --duration;
            yield return(new WaitForSeconds(1f));
        }

        dotted = false;

        particle.Stop();
    }
示例#28
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        bool damagePlayer = false;

        if (Input.GetKeyDown(KeyCode.Space))
        {
            // Collision with enemy
            EnemyHealth enemy = collision.gameObject.GetComponent <EnemyHealth> ();
            if (enemy != null)
            {
                // Kill the enemy
                EnemyHealth enemyHealth = enemy.GetComponent <EnemyHealth> ();
                if (enemyHealth != null)
                {
                    enemyHealth.Damage(enemyHealth.currentHealth);
                }

                damagePlayer = false;
            }
        }
    }
示例#29
0
    void OnTargetHit(EnemyHealth target, Vector3 location)
    {
        Debug.Log("Hit " + target + " with magic!");
        EnemyMovement movement = target.GetComponent <EnemyMovement>();
        float         damage   = Spell.sDamage;

        movement.animator.SetBool("damaged", true);
        target.Damage(damage, 1);
        target.hitContainer.active             = true;
        target.hitContainer.transform.position = location;
        //calculate correct rotation so that the player can see the label right
        float rotation = (movement.IsPlayerBehind()) ? 0f : 180f;

        target.hitContainer.transform.localRotation = Quaternion.identity;
        target.hitContainer.transform.Rotate(new Vector3(0f, rotation, 0f));

        target.hitMesh.text = "+ " + damage;
        ParticleSpawner parent = GetComponentInParent <ParticleSpawner>();

        parent.DeleteMsg(target);
    }
示例#30
0
    public void DashAttack()
    {
        for (int nCollider = 0; nCollider < m_skillTarget.m_listTargets.Count; nCollider++)
        {
            EnemyHealth enemyHealth = m_skillTarget.m_listTargets[nCollider].GetComponent <EnemyHealth>();

            if (enemyHealth != null)
            {
                enemyHealth.Damage
                (
                    m_nDashDamage,
                    transform.position,
                    10.0f,
                    E_SKILL_TYPE.E_SKILL_02,
                    "Audio/explosion_enemy"
                );
            }
        }

        Debug.Log("Used Dash Attack!");
    }