Example #1
0
    public virtual void Kill(Mario mario = null)
    {
        BoxCollider2D    coll  = GetComponent <BoxCollider2D>();
        AISimpleMovement move  = GetComponent <AISimpleMovement>();
        Enemy            enemy = GetComponent <Enemy>();

        Destroy(enemy);
        Destroy(move);
        Destroy(coll);
        rigidbody2D.AddForce(new Vector2(0.0f, 23000.0f));

        Vector3 newScale = transform.localScale;

        newScale.y          *= -1;
        transform.localScale = newScale;
        Destroy(gameObject, 5.0f);
    }
Example #2
0
    private void KillAllEnemies()
    {
        Vector2 topR, botL;

        topR = new Vector2(
            transform.position.x + _collider.bounds.extents.x,
            transform.position.y + _collider.bounds.extents.y * 3
            );
        botL = new Vector2(
            transform.position.x - _collider.bounds.extents.x,
            transform.position.y + _collider.bounds.extents.y
            );
        LayerMask mask = LayerMask.GetMask("Enemies", "Items", "RunningEnemies");

        Collider2D[] colls = Physics2D.OverlapAreaAll(topR, botL, mask);

        for (int i = 0; i < colls.Length; i++)
        {
            //if enemy, kill the enemy
            Enemy enemy = colls[i].GetComponent <Enemy>();
            if (enemy != null)
            {
                enemy.Kill();
            }
            //if item, make it jump
            else
            {
                colls[i].rigidbody2D.AddForce(new Vector2(0.0f, _force));

                //flip the item according to their position relative to the block
                if (transform.position.x > colls[i].transform.position.x)
                {
                    AISimpleMovement movable = colls[i].GetComponent <AISimpleMovement>();
                    if (movable.direction == DIRECTION.RIGHT)
                    {
                        movable.Flip();
                    }
                }
            }
        }
    }
Example #3
0
 void Start()
 {
     _animator = GetComponent <Animator>();
     _movement = GetComponent <AISimpleMovement>();
     startTime = Time.time;
 }