Ejemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D col)
    {
        PlayerControl player     = col.gameObject.GetComponent <PlayerControl>();
        ThrowEnemy    throwEnemy = col.gameObject.GetComponent <ThrowEnemy>();
        PlayerBat     bat        = col.gameObject.GetComponent <PlayerBat>();

        if (bat)
        {
            this.collider2D.enabled = false;
            DispatchMessage("OnHitByBat", this);
            this.directionX = 1;
            this.directionY = Random.Range(minimumYOffset, maximumYOffset);
            this.speed     *= hitByPlayerMultiplier;
            isHitBybat      = true;
            onHitSound.GetSound().Play();
            Invoke("OnDestroy", destroyTimeout);
            return;
        }

        if (throwEnemy && isHitBybat)
        {
            DispatchMessage("OnHitByThrowable", this);
            Destroy(this.gameObject);
        }

        if (player)
        {
            this.collider2D.enabled = false;
            player.OnDie();
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Called when either bat hits this ball.
    /// mainly about the speed calculating
    /// </summary>
    protected virtual void GetBatHit(Collision other)
    {
        PlayerBat hitPlayer = other.gameObject.GetComponent <PlayerBat>();

        if (hitPlayer.GetBatState() == (int)PlayerBat.BatState.none)
        {
            return;
        }

        ContactPoint contactPoint = other.contacts[0];
        //Vector3 curDir = m_Rb.velocity.normalized;
        //Vector3 newDir = Vector3.Reflect(curDir, contactPoint.normal);
        //Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, newDir);
        //transform.rotation = rotation;
        Vector3 newDir = contactPoint.normal;

        m_Rb.velocity = newDir.normalized * m_Rb.velocity.magnitude * 8f;
    }