Inheritance: MonoBehaviour, IDamageable
Ejemplo n.º 1
0
    void Detonate()
    {
        Vector3 explosionPosition = transform.position;

        Collider[] colliders = Physics.OverlapSphere(explosionPosition, radius);
        // get all the rigid bodies around
        foreach (Collider hit in colliders)
        {
            Rigidbody rb = hit.GetComponent <Rigidbody>();
            if (rb != null)
            {
                // deteach them if needed so they can fly around
                hit.transform.parent = null;
                // apply explosion force
                rb.AddExplosionForce(power, explosionPosition, radius, 3.0F);
            }
            // also apply delayed damage
            DamageableEntity entity = hit.GetComponent <DamageableEntity>();
            if (entity != null)
            {
                // check if they die instantly
                bool noDelay = hit.CompareTag("Player") || hit.CompareTag("Instant Death");
                entity.OnDamage(gameObject, damage, noDelay ? 0 : onDeathDelay);
            }
        }
        // destroy bomb too
        Destroy(gameObject);
    }
Ejemplo n.º 2
0
 public void Spawn(RoomInfo r)
 {
     room      = r;
     templates = GameObject.FindGameObjectWithTag("Rooms").GetComponent <EnemyTemplates>();
     if (r.type == "normal")
     {
         int numE = Random.Range(1, 4);
         for (int i = 0; i < numE; i++)
         {
             int              xOffset = Random.Range(-1, 2);
             int              yOffset = Random.Range(-1, 2);
             int              rand    = Random.Range(0, templates.enemies.Length);
             GameObject       enemy   = Instantiate(templates.enemies[rand], (Vector2)transform.position + new Vector2(xOffset, yOffset), Quaternion.identity);
             DamageableEntity de      = enemy.GetComponent <DamageableEntity>();
             if (de != null)
             {
                 de.spawnlist = this;
                 enemies.Add(de);
             }
         }
     }
     else if (r.type == "boss")
     {
     }
 }
    public override void HandleCollision(Collider collider, Collision collision)
    {
        if (shootInstigator == collider.gameObject)
        {
            return;
        }

        GameObject hitObject = collider.gameObject;

        DamageableEntity hitDamageableEntity = hitObject.GetComponent <DamageableEntity>();

        if (hitDamageableEntity)
        {
            if (hitDamageableEntity.GetDamageTag != damageTag && damageTag != DamageTag.Environment)
            {
                hitDamageableEntity.ReceiveDamage(projectileDamages, gameObject);
            }
        }
        else
        {
            AudioManager.PlaySound(defaultDestroySound);
        }

        DestroyProjectile();
    }
Ejemplo n.º 4
0
    void OnCollisionEnter(Collision col)
    {
        GetComponent <Rigidbody>().velocity = Vector3.zero;

        if (GetComponentInChildren <MeshRenderer>() != null)
        {
            GetComponentInChildren <MeshRenderer>().enabled = false;
        }
        else
        {
            Destroy(GetComponent <ParticleSystem>());
        }

        gameObject.transform.GetChild(1).transform.gameObject.SetActive(true);

        float time = gameObject.transform.GetChild(1).transform.gameObject.GetComponent <ParticleSystem>().time;

        _duration     = gameObject.transform.GetChild(1).transform.gameObject.GetComponent <ParticleSystem>().main.duration;
        _initDuration = gameObject.transform.GetChild(1).transform.gameObject.GetComponent <ParticleSystem>().main.duration;


        if (col.gameObject.tag == "Player" && !_didHit)
        {
            _didHit = true;

            DamageableEntity de = col.gameObject.GetComponent <DamageableEntity>();
            Debug.Log("TravellingSpell::playerWhoSpawnedUs: " + playerWhoSpawnedUs);
            de.TakeDamage(playerWhoSpawnedUs, _damageAmount);
            GetComponent <Collider>().enabled = false;
        }

        _didHit = true;
    }
Ejemplo n.º 5
0
 // Start is called before the first frame update
 void Start()
 {
     playerDamageableEntity = this.GetComponentInParent <DamageableEntity>();
     prevHealthValue        = playerDamageableEntity.health;
     healthSlider.maxValue  = playerDamageableEntity.health;
     healthSlider.value     = playerDamageableEntity.health;
 }
Ejemplo n.º 6
0
    private IEnumerator FireLaser()
    {
        while (true)
        {
            Ray        ray = new Ray(emissor.transform.position, emissor.transform.forward);
            RaycastHit hit;

            line.SetPosition(0, ray.origin);
            if (Physics.Raycast(ray, out hit, distance))
            {
                line.SetPosition(1, hit.point);
                target = hit.collider.gameObject.GetComponent <DamageableEntity>();
                //Debug.Log("Hitting: " + hit.collider.name + " with damageable entity? " + (target != null));
                if (hit.collider.CompareTag("Player") && target != null && !firstHit)
                {
                    DoDamage();
                    firstHit = true;
                }
                else
                {
                    // reset hit if it's not a damageable entity
                    firstHit = false;
                }
            }
            else
            {
                target   = null;
                firstHit = false;
                line.SetPosition(1, ray.GetPoint(distance));
            }
            yield return(null);
        }
    }
Ejemplo n.º 7
0
    private void Awake()
    {
        entity = GameObject.FindGameObjectWithTag("MainCharacter").GetComponentInChildren <DamageableEntity>();

        entity.OnHit    += UpdateBar;
        entity.OnRevive += UpdateBar;
    }
Ejemplo n.º 8
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        // Is it damageable?
        DamageableEntity damageable = collision.gameObject.GetComponent <DamageableEntity>();

        if (damageable)
        {
            if (onHit != null)
            {
                onHit.Invoke(collision.gameObject);
            }
            // Deal your damage
            // Possibility of a persistent projectile / hit-point system?

            if (OnAttackHit != null)
            {
                OnAttackHit.Invoke();
            }
            damageable.TakeDamage(Damage);
        }

        // Is it a ghost?
        Transform parent = collision.gameObject.transform.parent;

        if (parent != null)
        {
            GhostMovement ghost = parent.GetComponentInChildren <GhostMovement>();
            if (ghost != null)
            {
                ghost.Knockback(transform.up * knockbackForce);
            }
        }
    }
Ejemplo n.º 9
0
 public void Kill(DamageableEntity e)
 {
     if (enemies.Contains(e))
     {
         enemies.Remove(e);
         checkDestroy();
     }
 }
    private void Awake()
    {
        spriteRenderer   = GetComponent <SpriteRenderer>();
        damageableEntity = GetComponentInChildren <DamageableEntity>();

        damageableEntity.OnHit    += PlayerHit;
        damageableEntity.OnRevive += PlayerRevived;
    }
Ejemplo n.º 11
0
 private void Awake()
 {
     mainCamera       = Camera.main;
     damageableEntity = GetComponent <DamageableEntity>();
     InputController.Initialize(); //TODO Buscar una MUCHA mejor manera de llamar a esto.
     heroWeapon = gameObject.GetComponent <HeroWeapon>();
     damageableEntity.onDeath += () => EventsManager.DispatchEvent(new ParticleEvent(PrefabID.HeroDeath, transform.position, Quaternion.identity));
     damageableEntity.onDeath += () => EventsManager.DispatchEvent(new SoundEvent(SoundID.HeroDeath, transform.position));
 }
Ejemplo n.º 12
0
    void OnParticleCollision(GameObject other)
    {
        if (other.tag == "Player")
        {
            DamageableEntity de = other.GetComponent <DamageableEntity>();

            de.TakeDamage(SteamClient.Name, _damage);
        }
    }
Ejemplo n.º 13
0
    private void Awake()
    {
        respawnPoint   = transform.position;
        movementBody   = GetComponent <Rigidbody2D>();
        damageable     = GetComponentInChildren <DamageableEntity>();
        playerDetector = GetComponentInChildren <PlayerDetector>();

        damageable.OnRevive          += Respawn;
        playerDetector.OnPlayerEnter += OnPlayerDetected;
    }
Ejemplo n.º 14
0
    private void OnCollisionEnter(Collision collision)
    {
        //Debug.Log("HIT : " + collision.gameObject);
        DamageableEntity colEntity = collision.gameObject.GetComponent <DamageableEntity>();

        if (colEntity != null && colEntity.friendlyToPlayer != friendlyToPlayer && canDamage)
        {
            collision.gameObject.GetComponent <DamageableEntity>().takeDamage(damage);
        }
    }
Ejemplo n.º 15
0
    private IEnumerator FireLaser()
    {
        while (true)
        {
            Ray        ray = new Ray(emissor.transform.position, emissor.transform.forward);
            RaycastHit hit;

            line.SetPosition(0, ray.origin);
            if (Physics.Raycast(ray, out hit, distance))
            {
                //Debug.Log("Hitting: " + hit.collider.name + " with damageable entity? " + (target != null));
                line.SetPosition(1, hit.point);
                target          = hit.collider.gameObject.GetComponent <DamageableEntity>();
                switchActivator = hit.collider.gameObject.GetComponent <SwitchActivator>();
                if (hit.collider.CompareTag("Player") && target != null && !firstHit)
                {
                    DoDamage();
                    firstHit = true;
                }
                else
                {
                    // reset hit if it's not a damageable entity
                    firstHit = false;
                }
                // check if switch
                //switchActivator = hit.collider.gameObject.GetComponent<SwitchActivator>();
                if (switchActivator != null && switchActivator != lastSwitchActivator)
                {
                    switchActivator.Activate(gameObject);
                    lastSwitchActivator = switchActivator;
                }
                // check if previous switch is differnt or it's not hitting a switch anymore
                if (lastSwitchActivator != null && switchActivator == null)//(switchActivator == null || lastSwitchActivator != switchActivator))
                {
                    //Debug.Log("Desactivate wat");
                    lastSwitchActivator.Desactivate();
                    lastSwitchActivator = null;
                }
                //lastSwitchActivator = switchActivator;
            }
            else
            {
                if (switchActivator != null)
                {
                    switchActivator.Desactivate();
                    switchActivator     = null;
                    lastSwitchActivator = null;
                }
                target   = null;
                firstHit = false;
                line.SetPosition(1, ray.GetPoint(distance));
            }
            yield return(null);
        }
    }
Ejemplo n.º 16
0
 public void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Enemy"))
     {
         DamageableEntity damageableEntity = other.gameObject.GetComponent <DamageableEntity>();
         if (damageableEntity)
         {
             damageableEntity.OnDamage(gameObject, damage);
         }
     }
 }
Ejemplo n.º 17
0
    private void Awake()
    {
        defeatedEnemyCount = 0;
        for (int i = 0; i < enemies.Count; i++)
        {
            DamageableEntity death = enemies[i].GetComponentInChildren <DamageableEntity>();
            death.OnDeath += OnEnemyDeath;
        }

        nextLevelDetector.OnPlayerEnter += CompleteLevel;
    }
Ejemplo n.º 18
0
    protected virtual void OnCollisionEnter(Collision collisionInfo)
    {
        KillThisObject();

        DamageableEntity d = collisionInfo.collider.GetComponent <DamageableEntity>();

        if (d != null)
        {
            d.TakeDamage(damage);
        }
    }
Ejemplo n.º 19
0
    protected virtual void OnCollisionEnter(Collision collision)
    {
        DamageableEntity de = null;

        if (damage > 0 &&
            (de = collision.gameObject.GetComponent <DamageableEntity>()) != null)
        {
            //de.TakeDamage(this, damage);
            //de.networkObject.SendRpc(RPC_SERVER__TAKE_DAMAGE, Receivers.All, damage);
        }
    }
Ejemplo n.º 20
0
    public void HandleCollision(RaycastHit hit, Vector3 initialMovementDirection)
    {
        InterruptTrajectory();
        DemandeFx(hit.point);

        if (hit.collider.gameObject.layer == 12)
        {
            SoundManager.Instance.PlaySound(Sound.ShieldGetHit, hit.transform.position);
            FxManager.Instance.CreateFx(FxType.genericImpact, hit.point);
        }
        else if (hit.collider.gameObject.layer == 14)
        {
            SoundManager.Instance.PlaySound(Sound.WallGetHit, hit.transform.position);
            FxManager.Instance.CreateFx(FxType.genericImpact, hit.point);
        }

        Vector3 horizontalNormal = hit.normal;

        horizontalNormal.y = 0;
        horizontalNormal.Normalize();

        // Place disc as close from the hit point as possible
        Vector3 newPos = hit.point + horizontalNormal * (myCollider.radius + 0.01f);

        newPos.y           = 0;
        transform.position = newPos;

        // Gives the disc a knockback to simulate a rebound
        Vector3 reflectedDirection = Vector3.Reflect(initialMovementDirection, horizontalNormal);

        knockbackSystem.ReceiveKnockback(DamageTag.Environment, GetReboundOnObjectKnockback(), reflectedDirection);

        DamageableEntity hitDamageableEntity = hit.collider.GetComponent <DamageableEntity>();

        if (hitDamageableEntity != null)
        {
            hitDamageableEntity.ReceiveDamage(damageTag, new DamagesParameters(currentDamagesAmount, numberOfStunedTurns));

            lastObjTouch = hitDamageableEntity.gameObject;
            SoundManager.Instance.PlaySound(Sound.EnemyDamaged, hitDamageableEntity.transform.position);
        }

        if (effectZoneToInstantiateOnHit != EffectZoneType.None)
        {
            EffectZone newEffectZone = EffectZonesManager.Instance.GetEffectZoneFromPool(effectZoneToInstantiateOnHit);
            newEffectZone.StartZone(GetColliderCenter);

            if (destroyOnHit)
            {
                DiscManager.Instance.DestroyDisc(this);
            }
        }
    }
Ejemplo n.º 21
0
    void Awake()
    {
        if (photonView.IsMine)
        {
            playerControl.LocalPlayerInstance = this.gameObject;
            ourDamageableEntity = GetComponent <DamageableEntity> ();
        }

        playerNicknameText.text = photonView.Owner.NickName;

        DontDestroyOnLoad(this.gameObject);
    }
Ejemplo n.º 22
0
    /// <summary>
    /// Returns true if something was hit, and therefore the movement needs to stop
    /// </summary>
    /// <param name="startPosition"></param>
    /// <param name="endPos"></param>
    /// <returns></returns>
    public bool TryToMoveFromTo(Vector3 startPosition, Vector3 endPos)
    {
        Vector3 direction = endPos - startPosition;
        float   distance  = direction.magnitude;

        direction.Normalize();

        startPosition += myCollider.center;
        endPos        += myCollider.center;

        RaycastHit hit = new RaycastHit();

        if (Physics.SphereCast(startPosition, myCollider.radius, direction, out hit, distance, GetTrajectoryCheckLayerMask))
        {
            if (hit.collider.gameObject.layer != 10 || blockedByEnemies)
            {
                // test bouclier
                if (hit.collider.gameObject.layer == 12)
                {
                    Transform hitParent = hit.transform.parent;
                    if (hitParent != null)
                    {
                        ShieldManager objShielManager = hit.transform.parent.GetComponent <ShieldManager>();

                        if (objShielManager != null)
                        {
                            if (objShielManager.myObjParent == lastObjTouch)
                            {
                                return(false);
                            }
                        }
                    }
                }

                HandleCollision(hit, direction);

                return(true);
            }
            else
            {
                DamageableEntity hitDamageableEntity = hit.collider.GetComponent <DamageableEntity>();
                if (hitDamageableEntity != null)
                {
                    hitDamageableEntity.ReceiveDamage(damageTag, new DamagesParameters(currentDamagesAmount, numberOfStunedTurns));

                    lastObjTouch = hitDamageableEntity.gameObject;
                }
            }
        }

        return(false);
    }
    public override void HandleCollision(Collider collider, Collision collision)
    {
        GameObject hitObject = collider.gameObject;

        if (shootInstigator == hitObject)
        {
            return;
        }

        bool mustDestroy          = false;
        bool preventDestroyOnWall = false;

        ProjectileBase hitProjectile = hitObject.GetComponent <ProjectileBase>();

        if (hitProjectile)
        {
            preventDestroyOnWall = true;
        }

        if (!preventDestroyOnWall && collision != null)
        {
            Vector3        averageNormal = Vector3.zero;
            ContactPoint[] points        = collision.contacts;
            foreach (ContactPoint point in points)
            {
                averageNormal += point.normal;
            }
            averageNormal /= points.Length;

            if (Mathf.Abs(Vector3.Dot(averageNormal, Vector3.up)) < 0.5f)
            {
                mustDestroy = true;
            }
        }

        DamageableEntity hitDamageableEntity = hitObject.GetComponent <DamageableEntity>();

        if (hitDamageableEntity)
        {
            if (hitDamageableEntity.GetDamageTag != damageTag && damageTag != DamageTag.Environment)
            {
                hitDamageableEntity.ReceiveDamage(projectileDamages, gameObject);
            }

            mustDestroy = true;
        }

        if (mustDestroy)
        {
            DestroyProjectile();
        }
    }
Ejemplo n.º 24
0
    void CollisionAttack()
    {
        List <GameObject> _objsTouched = GetListOfObjsTouched();

        foreach (GameObject _obj in _objsTouched)
        {
            DamageableEntity hitDamageableEntity = _obj.GetComponent <DamageableEntity>();
            if (hitDamageableEntity != null && hitDamageableEntity.gameObject != player)
            {
                hitDamageableEntity.ReceiveDamage(DamageTag.Enemy, new DamagesParameters(damage));
            }
        }
    }
Ejemplo n.º 25
0
    private void Awake()
    {
        if (!toDisable)
        {
            toDisable = gameObject;
        }
        if (!damageable)
        {
            damageable = GetComponentInChildren <DamageableEntity>();
        }

        damageable.OnDeath += Die;
    }
Ejemplo n.º 26
0
 /// <summary>
 /// Does damage to the given object only if the component is enabled
 /// and the object is one of the targets of this component.
 /// </summary>
 /// <param name="obj">Object to apply damage to.</param>
 /// <returns>True if the object received any damage.</returns>
 protected bool DoDamage(GameObject obj)
 {
     // First check if the object's layer corresponds to the targetLayerMask
     if (isActive && IsEntityTarget(obj))
     {
         // maybe do othe checks here later
         // check if the object is damagable
         DamageableEntity entity = obj.GetComponent <DamageableEntity>();
         if (entity)
         {
             return(entity.OnDamage(gameObject, damage));
         }
     }
     return(false);
 }
Ejemplo n.º 27
0
    protected override void OnCollisionEnter(Collision collision)
    {
        DamageableEntity de = collision.gameObject.GetComponent <DamageableEntity>();

        if (damage > 0 & de != null)
        {
            foreach (System.Type t in targets)
            {
                if (de.GetComponent(t) != null)
                {
                    //de.TakeDamage(gameObject, damage);
                    break;
                }
            }
        }
    }
Ejemplo n.º 28
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        // Is it damageable?
        DamageableEntity damageable = collision.gameObject.GetComponent <DamageableEntity>();

        if (damageable)
        {
            if (onHit != null)
            {
                onHit.Invoke(collision.gameObject);
            }
            // Deal your damage
            // Possibility of a persistent projectile / hit-point system?
            Debug.Log("Hit!" + collision.name);
            damageable.TakeDamage(Damage);
        }
    }
Ejemplo n.º 29
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        GameObject hitObject = other.gameObject;

        if (OnImpact != null)
        {
            OnImpact();
        }

        DamageableEntity hitEntity = hitObject.GetComponent <DamageableEntity>();

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

        Remove();
    }
Ejemplo n.º 30
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        // Is it damageable?
        DamageableEntity damageable = collision.gameObject.GetComponentInChildren <DamageableEntity>();

        if (damageable)
        {
            if (onHit != null)
            {
                onHit.Invoke(collision.gameObject);
            }

            // Deal your damage
            damageable.TakeDamage(Damage);

            // Have a refresh system so you can take damage many times if he's over you all the time
            StartCoroutine(RefreshHitbox());
        }
    }