Ejemplo n.º 1
0
    public override void Damage(GameObject _object)
    {
        PlayerBehaviour player = _object.GetComponent <PlayerBehaviour>();

        player.Damage(monster.GetDamage());
        player.KnockBack(knockBackPower, player.GetDirectionToVector3(transform.position));
    }
Ejemplo n.º 2
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Player")
     {
         playerBe.Damage(1);
         Debug.Log("Collided");
     }
 }
Ejemplo n.º 3
0
 void OnTriggerEnter2D(Collider2D collidedCollider)
 {
     if (collidedCollider.tag == "Player")
     {
         PlayerBehaviour playerBehaviour = collidedCollider.GetComponent <PlayerBehaviour>();
         if (playerBehaviour != null)
         {
             playerBehaviour.Damage();
             Damage();
         }
     }
 }
Ejemplo n.º 4
0
    void OnParticleCollision(GameObject other)
    {
        if (canHit)
        {
            Rigidbody r = other.GetComponent <Rigidbody>();
            if (r)
            {
                PlayerBehaviour     pB = r.GetComponent <PlayerBehaviour>();
                AIBehaviour         aB = r.GetComponent <AIBehaviour>();
                BossBehaviour       bB = r.GetComponent <BossBehaviour>();
                GiantLaserBehaviour gB = r.GetComponent <GiantLaserBehaviour>();
                if (pB)
                {
                    if (!pB.invinsible & !playerImune)
                    {
                        pB.Damage(damageDealt);
                    }
                }
                if (!enemyImune)
                {
                    if (aB)
                    {
                        aB.Damage(damageDealt);

                        aB.ToggleGotHit();
                    }

                    if (bB)
                    {
                        bB.Damage(damageDealt);
                    }
                    if (gB)
                    {
                        gB.Damage(damageDealt);
                    }
                }
                //Vector3 direction = other.transform.position - transform.position;
                //direction = direction.normalized;
                //r.AddForce(direction * 5);
                //Destroy(gameObject);
                canHit = false;
                StartCoroutine(SetCanHitTrue());
            }
        }
    }
Ejemplo n.º 5
0
    private void FireAtAimTarget()
    {
        if (turretType == TurretType.Laser)
        {
            if (firingBeam == false)
            {
                //Start of firing
            }
            if (elapsedFiringTime < maxFiringTime)
            {
                elapsedFiringTime += Time.deltaTime;
                aimTarget          = Vector2.Lerp(aimTarget, (Vector2)target.position, Time.deltaTime * firingTargetSpeed);
                firingBeam         = true;
            }
            else
            {
                firingBeam             = false;
                beamLength             = 0f;
                laserBeamRenderer.size = Vector2.zero;
                elapsedFiringTime      = 0f;
                elapsedTargetingTime   = 0f;
                return;
            }

            RaycastHit2D hit = Physics2D.Raycast(transform.position, target.position - transform.position, beamLength, visionBlockers);
            if (hit)
            {
                //Instantiate Laser Wall Hit anim object here
                PlayerBehaviour lPlayer = hit.collider.GetComponent <PlayerBehaviour>();
                if (lPlayer != null)
                {
                    lPlayer.Damage(1);
                }
            }
            else
            {
                beamLength = elapsedFiringTime * beamLengthScalar;
            }

            laserBeamRenderer.size = Vector2.right * beamLength + Vector2.up;
            float lAngle = Vector2.Angle(aimTarget - (Vector2)transform.position, Vector2.right);
            laserBeamRenderer.gameObject.transform.localEulerAngles = Vector3.forward * ((aimTarget.y > transform.position.y) ? lAngle : -lAngle);
        }
    }
Ejemplo n.º 6
0
 void Update()
 {
     if (attack == false)
     {
         transform.LookAt(target.transform);
         transform.position = Vector3.MoveTowards(transform.position, targetPos, speed * Time.deltaTime);
         anim.SetFloat("Speed", 2f);
     }
     else
     {
         if (attackTimer < 0)
         {
             player.Damage(damage);
             attackTimer = rateOfAttack;
         }
         else
         {
             attackTimer -= Time.deltaTime;
         }
         anim.SetFloat("Speed", 0f);
     }
 }
Ejemplo n.º 7
0
    void OnCollisionEnter()
    {
        //get all the colliders inside the radius
        Collider[] collider = Physics.OverlapSphere(transform.position, explosionRadius);

        for (int i = 0; i < collider.Length; i++)
        {
            //

            //your code


            //
            Rigidbody r = collider[i].GetComponent <Rigidbody>();
            if (r)
            {
                PlayerBehaviour pB = r.GetComponent <PlayerBehaviour>();

                if (pB)
                {
                    pB.Damage(damage / Vector3.Distance(transform.position, pB.transform.position));
                    if (!pB.ragdollh.ragdolled)
                    {
                        pB.ToggleRagdoll();
                    }
                }
                r.AddExplosionForce(explosionForce, transform.position, explosionRadius);
            }
        }
        Instantiate(particle, transform.position, Quaternion.identity);
        if (trail)
        {
            trail.transform.parent = null;
        }
        Destroy(gameObject);
    }
Ejemplo n.º 8
0
    void OnCollisionEnter()
    {
        if (!collided)
        {
            if (audioS)
            {
                audioS.PlayOneShot(collideAudio);
            }

            //get all the colliders inside the radius
            Collider[] collider = Physics.OverlapSphere(transform.position, explosionRadius);
            for (int i = 0; i < collider.Length; i++)
            {
                //
                Rigidbody r = collider[i].GetComponent <Rigidbody>();
                if (r)
                {
                    PlayerBehaviour     pB = r.GetComponent <PlayerBehaviour>();
                    AIBehaviour         aB = r.GetComponent <AIBehaviour>();
                    BossBehaviour       bB = r.GetComponent <BossBehaviour>();
                    GiantLaserBehaviour gB = r.GetComponent <GiantLaserBehaviour>();

                    Vector3 closetPoint = collider[i].ClosestPointOnBounds(transform.position);
                    float   damageDealt = damage - Vector3.Distance(transform.position, closetPoint) * (damage / explosionRadius);
                    if (pB)
                    {
                        if (!pB.invinsible & !playerImune)
                        {
                            if (damageDealt > 0)
                            {
                                pB.Damage(damageDealt);
                                if (!pB.ragdollh.ragdolled)
                                {
                                    pB.playerAnimator.SetTrigger("GotHit");
                                    if (explosionForce > 10)
                                    {
                                        pB.ToggleRagdoll();
                                        if (!pB.dead)
                                        {
                                            pB.StandUpAfter(2f);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!enemyImune)
                    {
                        if (aB)
                        {
                            if (damageDealt > 0)
                            {
                                aB.Damage(damageDealt);

                                aB.ToggleGotHit();
                            }
                        }

                        if (bB)
                        {
                            if (damageDealt > 0)
                            {
                                bB.Damage(damageDealt);
                            }
                        }
                        if (gB)
                        {
                            if (damageDealt > 0)
                            {
                                gB.Damage(damageDealt);
                            }
                        }
                    }
                    r.AddExplosionForce(explosionForce, transform.position, explosionRadius);
                }
            }
            if (particle)
            {
                Instantiate(particle, transform.position, Quaternion.identity);
            }
            if (trail)
            {
                trail.transform.parent = null;
            }
            collided = true;
            gameObject.GetComponentInChildren <Renderer>().enabled = false;
            try
            {
                gameObject.GetComponentInChildren <ParticleSystem>().Stop();
            }
            catch
            {
                ;
            }
            if (audioS)
            {
                audioS.PlayOneShot(collideAudio);
            }
            StartCoroutine(DestroyThis(1f));
        }
    }