Example #1
0
    /// <summary>
    /// only call from local player
    /// </summary>
    /// <param name="collision"></param>
    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Bullet"))
        {
            HitParam hit = collision.GetComponent <Bullet>().hitParam;

            Rigidbody2D body = rb2d;

            if (!isLocalPlayer)
            {
                body = GetComponent <MySyncPosition>().puppet.GetComponent <Rigidbody2D>();
            }

            if (hit.direction == "right")
            {
                body.AddForce(new Vector2(hit.forceBack * 5, 0));
            }
            else
            {
                body.AddForce(new Vector2(-hit.forceBack * 5, 0));
            }

            currentStat.hp -= hit.dame;
            if (currentStat.hp < 0)
            {
                playerCommand.Die();
            }
        }
    }