Exemplo n.º 1
0
    private void DoBulletHit()
    {
        if (radius == 0)
        {
            target.GetComponent <enemy>().TakeDamage(damage);
            Destroy(gameObject);
        }
        else
        {
            Collider[] cols = Physics.OverlapSphere(transform.position, radius);

            foreach (Collider c in cols)
            {
                enemy e = c.GetComponent <enemy>();
                if (e != null)
                {
                    e.TakeDamage(damage);
                    //e.GetComponent<enemy>().TakeDamage(damage);
                }
            }
        }

        // Get rid of bullet.
        Destroy(gameObject);
    }
Exemplo n.º 2
0
    void shoot()
    {
        muzzleFlash.Play();

        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            if (hit.collider.tag == "Enemy")
            {
                StartCoroutine(CourseCoroutine());
                Object.GetComponent <MeshRenderer>().material  = red;
                Object2.GetComponent <MeshRenderer>().material = red;
            }

            Debug.Log(hit.transform.name);

            enemy enemy = hit.transform.GetComponent <enemy>();

            if (enemy != null)
            {
                enemy.TakeDamage(damage);
            }
        }
    }
Exemplo n.º 3
0
    IEnumerator Shoot(float seconds)
    {
        while (firing)
        {
            muzzleFlashRight.Play();
            muzzleFlashLeft.Play();

            RaycastHit hit;
            if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
            {
                enemy planeZero = hit.transform.GetComponent <enemy>();

                if (planeZero != null)
                {
                    planeZero.TakeDamage(damage);
                }
            }

            int count = 0;
            while (count < duration)
            {
                ObjectToShake.transform.Translate(Mathf.Cos(Random.value) * ShakeSize.x, Mathf.Cos(Random.value) * ShakeSize.y, Mathf.Cos(Random.value) * ShakeSize.z);
                ShakeSize *= -1;
                yield return(new WaitForSeconds(0.02f));

                count++;
            }
            ObjectToShake.transform.localPosition = posInitial;

            yield return(new WaitForSeconds(seconds));
        }
    }
Exemplo n.º 4
0
    // set laser position, and enable it
    private void Laser( )
    {
        if (targetEnemy != null)
        {
            // call get damage and pass the amount of damage
            targetEnemy.TakeDamage(damageOverTime * Time.deltaTime);
            targetEnemy.Slow(slowPct);
            laserSound.enabled = true;
        }

        // set the position of the laser beam from the Leaser beam to the target
        lineRenderer.SetPosition(0, firePoint.position);
        lineRenderer.SetPosition(1, target.position);

        // get the position of enemy looking back to the turret
        Vector3 dir = firePoint.position - target.position;

        // set the position of the Particle system [ we need to offset it by by half from the center of the enemy ]
        impactEffect.transform.position = target.position + dir.normalized;
        // set the rotation of the Particle system
        impactEffect.transform.rotation = Quaternion.LookRotation(dir);

        // enable the object line renderer
        if (!lineRenderer.enabled)
        {
            lineRenderer.enabled = true;
            impactEffect.Play();
            leaserLight.enabled = true;
        }
    }
Exemplo n.º 5
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        if (hitInfo.gameObject.tag == "Enemy")
        {
            enemy enemy = hitInfo.gameObject.GetComponent <enemy>();
            //hitInfo.gameObject.tag == "Enemy"
            if (enemy != null)
            {
                enemy.TakeDamage(damage);
                Destroy(gameObject);
            }
        }



        if (hitInfo.gameObject.CompareTag("Wall"))
        {
            if (bounce)
            {
                transform.Rotate(0f, 180, 0f);
                rb.velocity = -1f * rb.velocity;
                bounce      = false;
            }
            else
            {
                Destroy(gameObject);
            }
        }
    }
Exemplo n.º 6
0
 void ExplosionDamage(Transform Enemy)
 {
     e = Enemy.GetComponent <enemy>();
     if (e != null)
     {
         GameObject BurnEffect = Instantiate(BurnEffectPrefab, Enemy.position, Quaternion.identity);
         BurnEffect.transform.parent = Enemy;
         if (e.isFly)
         {
             e.TakeDamage(enableblood, isIceDamage, ExplodeDamage / 3, 0);
         }
         else
         {
             e.TakeDamage(enableblood, isIceDamage, ExplodeDamage, 0);
         }
     }
 }
Exemplo n.º 7
0
 void OnTriggerEnter2D(Collider2D hitInfo)
 {
     enemy enemy = hitInfo.GetComponent<enemy>();
     if (enemy != null)
     {
         enemy.TakeDamage(damage);
     }
     Destroy(gameObject);
 }
Exemplo n.º 8
0
    void Damage(Transform enemyToDamage)
    {
        enemy e = enemyToDamage.GetComponent <enemy>();

        if (e != null)
        {
            e.TakeDamage(damage);
        }
    }
Exemplo n.º 9
0
    void Damage(Transform en)
    {
        enemy e = en.GetComponent <enemy>();

        if (e != null)
        {
            e.TakeDamage(damage, owner);
        }
    }
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        enemy enemy = hitInfo.GetComponent <enemy>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }
        Instantiate(impactEffect, transform.position, transform.rotation);
        Destroy(gameObject);
    }
Exemplo n.º 11
0
    // Damage the target
    void Damage(Transform enemy)
    {
        // get specific Component from the Transform enemy using GetComponent<>
        enemy e = enemy.GetComponent <enemy>();

        if (e != null)
        {
            // call get damage and pass the amount of damage
            e.TakeDamage(damage);
        }
    }
Exemplo n.º 12
0
    public void shoot()
    {
        RaycastHit hit;

        if (Physics.Raycast(fps_cam.transform.position, (fps_cam.transform.forward), out hit, range))
        {
            enemy mimic = hit.transform.GetComponent <enemy>();
            if (mimic != null)
            {
                mimic.TakeDamage(damage);
            }
        }
    }
Exemplo n.º 13
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        enemy enemy = hitInfo.GetComponent <enemy>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }
        GameObject effect = Instantiate(hitEffect, transform.position, Quaternion.identity);

        Destroy(effect, 5f);
        Destroy(gameObject);
    }
Exemplo n.º 14
0
    void Shoot()
    {
        RaycastHit2D hitInfo = Physics2D.Raycast(shootshoot.position, shootshoot.right);

        if (hitInfo)
        {
            enemy enemy = hitInfo.transform.GetComponent <enemy>();
            if (enemy != null)
            {
                enemy.TakeDamage(damage);
            }
        }
    }
Exemplo n.º 15
0
    void OnTriggerEnter(Collider other)
    {
        enemy enemyhit = other.gameObject.GetComponent <enemy>();

        if (enemyhit != null)
        {
            enemyhit.TakeDamage(missileDamage);
            Debug.Log("damage given");
        }
        Debug.Log("impact");
        // Destroy(gameObject);
        Die = true;
    }
Exemplo n.º 16
0
 void Damage(Transform TransformEnemy)
 {
     e = TransformEnemy.GetComponent <enemy>();
     if (e != null)
     {
         if (explosionRadius > 0)
         {
             GameObject BurnEffect = Instantiate(BurnEffectPrefab, e.transform.position, Quaternion.identity);
             BurnEffect.transform.parent = e.transform;
             //	GameObject ExplodeEffectInfo = Instantiate (ExplodeEffect,TransformEnemy.position,Quaternion.identity);
             //	Destroy(ExplodeEffectInfo,5f);
         }
         e.TakeDamage(enableblood, isIceDamage, damage, 0);
     }
 }
Exemplo n.º 17
0
 void OnMouseDown()
 {
     Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius);
     foreach (Collider2D collider in colliders)
     {
         Debug.Log("sadsadsdas");
         if (collider.tag == "enemy")
         {
             Debug.Log("enemyHIT");
             enemy enemy = collider.GetComponent <enemy>();
             enemy.TakeDamage(false, false, 800, 0);
         }
     }
     Prop.fire();
     Destroy(gameObject);
 }
Exemplo n.º 18
0
    void FireLasers()
    {
        StartCoroutine("laserFlash");
        RaycastHit hit;

        if (Physics.Raycast(ship.transform.position, ship.transform.forward, out hit, laserRange))
        {
            //hit.transform is the object you hit
            enemy enemyhit = hit.transform.GetComponent <enemy>();
            if (enemyhit != null)
            {
                enemyhit.TakeDamage(laserDamage);
                laser.SetPosition(1, hit.transform.position);
            }
        }
    }
Exemplo n.º 19
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        enemy Enemy = collision.GetComponent <enemy>();

        if (Enemy != null)
        {
            Enemy.TakeDamage(Power);
            Instantiate(particle, transform.position, transform.rotation);
            Destroy(gameObject);
        }
        if (collision.name != "Player")
        {
            Instantiate(particle, transform.position, transform.rotation);
            Destroy(gameObject);
        }
    }
Exemplo n.º 20
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        Debug.Log(hitInfo.name);

        enemy enemyRef = hitInfo.gameObject.GetComponent <enemy>();

        if (enemyRef != null)
        {
            Debug.Log("enemyHit");

            enemyRef.TakeDamage(damage);
        }

        Debug.Log("explode!!!");
        //Instantiate(impactEffect, transform.position, transform.rotation);

        Destroy(gameObject);
    }
Exemplo n.º 21
0
    //raycast method
    void shoot()
    {
        //Plays particle on shoot for gun effect
        gunFlash.Play();
        //declare Raycast for gun
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);

            enemy target = hit.transform.GetComponent <enemy>();
            //Checks if Raycast hit something for it to takedamage
            if (target != null)
            {
                //calls public command from enemy to take damage
                target.TakeDamage(damage);
            }
        }
    }
Exemplo n.º 22
0
    void Laser()
    {
        targetEnemy.TakeDamage(damageOverTime * Time.deltaTime);
        targetEnemy.Slow(slowAmount);

        if (!lineRenderer.enabled)
        {
            lineRenderer.enabled = true;
            impactEffect.Play();
            impactLight.enabled = true;
        }

        lineRenderer.SetPosition(0, firePoint.position);
        lineRenderer.SetPosition(1, target.position);

        Vector3 dir = firePoint.position - target.position;

        impactEffect.transform.rotation = Quaternion.LookRotation(dir);
        impactEffect.transform.position = target.position + 0.25f * dir.normalized;
    }
Exemplo n.º 23
0
    void OnTriggerEnter2D(Collider2D _collision)
    {
        if (_collision.CompareTag("Enemy"))
        {

            enemy _enemy = _collision.GetComponent<enemy>();
                _enemy.TakeDamage(_Damage);
                Global_Script.scorePoint += _enemy.chars[_enemy.chousenChar].GetComponent<Char>().costEnemy;
                DestroySnowBall();
      
        }
        if (_collision.CompareTag("Player"))
        {
            Player _player = _collision.GetComponent<Player>();
                _player.TakeDamage(_Damage);
                DestroySnowBall();
        }
        
       
    }
Exemplo n.º 24
0
    void Shoot()
    {
        RaycastHit hit;

        if (fireTimer < fireRate || currentBullets <= 0)
        {
            return;
        }


        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, Convert.ToInt32(range)))
        {
            //Debug.Log(hit.transform.name);
            enemy target = hit.transform.GetComponent <enemy>();

            if (target != null && hit.rigidbody != null)
            {
                target.TakeDamage(damage);
                GameObject impactBlood = Instantiate(impactEffectBlood, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(impactBlood, 0.5f);
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }
            else
            {
                GameObject impactGameObject = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(impactGameObject, 0.5f);
            }
        }
        muzzleFlash.Play();
        PlayShootSound();
        anim.CrossFadeInFixedTime("Fire", 0.1f);

        currentBullets--;
        UpdateBulletsText();

        fireTimer = 0.0f; //reset fire timer
    }
Exemplo n.º 25
0
    void Laser()
    {
        if (!AttackPlayer)
        {
            targetEnemy.TakeDamage(damageOverTime * Time.deltaTime);
            targetEnemy.Slow(slowAmount);
            if (Type == 4)
            {
                targetEnemy.AddSpeed(2);
            }
        }
        else
        {
            targetPlayerLife.TakeDamage(damageOverTime * Time.deltaTime);
            targetPlayerSpeed.Slow(slowAmount);
            if (Type == 4)
            {
                targetPlayerSpeed.AddSpeed(2);
            }
        }

        if (!lineRenderer.enabled)
        {
            lineRenderer.enabled = true;
            impactEffect.Play();
            impactLight.enabled = true;
        }
        lineRenderer.SetPosition(0, firePoint.position);
        lineRenderer.SetPosition(1, target.position);

        Vector3 dir = firePoint.position - target.position;

        impactEffect.transform.position = target.position + 12 * dir.normalized;

        impactEffect.transform.rotation = Quaternion.LookRotation(dir);
    }
Exemplo n.º 26
0
    //raycast method
    void shoot()
    {
        //Plays particle on shoot for gun effect
        gunFlash.Play();
        //declare Raycast for gun
        RaycastHit hit;
        Vector3    Direction = fpsCam.transform.forward;

        Direction.x += Random.Range(-0.1f, 0.1f);
        Direction.y += Random.Range(-0.1f, 0.1f);
        Direction.z += Random.Range(-0.1f, 0.1f);
        if (Physics.Raycast(fpsCam.transform.position, Direction, out hit, range))
        {
            Debug.Log(hit.transform.name);
            Debug.DrawLine(fpsCam.transform.position, hit.point, Color.green);
            enemy target = hit.transform.GetComponent <enemy>();
            //Checks if Raycast hit something for it to takedamage
            if (target != null)
            {
                //calls public command from enemy to take damage
                target.TakeDamage(damage);
            }
        }
    }