Ejemplo n.º 1
0
    public void CmdFire(Vector3 start, Vector3 end)
    {
        RaycastHit hitInfo;

        if (Physics.Raycast(start, end - start, out hitInfo, 10f, ~shootingMask.value))
        {
            Debug.Log("Raycasthit, woho");
            Target hitTarget = hitInfo.collider.GetComponentInParent <Target>();
            if (hitTarget != null)
            {
                Vector3       offset        = hitInfo.point - hitTarget.Center.position;
                TargetHitInfo targetHitInfo = hitTarget.CreateHitInfo(offset);
                RpcShowHitFire(start, hitTarget.GetNetId(), offset);
                hitTarget.RpcHideTargetForDestruction();
                hitTarget.CmdRegisterHitDestroyAfterTime();

                scoreManager.CmdNotifyTargetDestroyed(
                    targetHitInfo,
                    GetComponent <NetworkIdentity>().netId
                    );
            }
            else
            {
                RpcShowFire(start, end);
            }
        }
        else
        {
            RpcShowFire(start, end);
        }

        Debug.Log("hitInfo.collider: " + hitInfo.collider);
    }
Ejemplo n.º 2
0
    public void CmdNotifyTargetDestroyed(TargetHitInfo hitInfo, NetworkInstanceId shooterId)
    {
        int shooterPoints = (int)Mathf.Clamp((int)(hitInfo.maxPoints * (1 - hitInfo.elapsedTime / hitInfo.lifetime) * hitInfo.precision), 1, hitInfo.maxPoints);
        int ownerPoints   = hitInfo.maxPoints - shooterPoints;

        var shooterScore = GetPlayerScore(shooterId);

        shooterScore.Increase(shooterPoints);
        RpcUpdatePlayerTotalScore(shooterId, shooterScore.TotalScore);

        var ownerScore = GetPlayerScore(hitInfo.ownerId);

        ownerScore.Increase(ownerPoints);
        RpcUpdatePlayerTotalScore(hitInfo.ownerId, ownerScore.TotalScore);

        RpcShowScoreForPlayer(shooterId, hitInfo.targetId, shooterPoints, hitInfo.maxPoints);
        RpcShowScoreForPlayer(hitInfo.ownerId, hitInfo.targetId, ownerPoints, hitInfo.maxPoints);
    }