0

am new here sorry if am posting wrong you can ask me for more info if am not gived much in code. I try to fix my issue but its anoying like 5 days now in row i try every method to fix it but it wont help. The real problem is my screen starts flashning in black after some time my scopes in game losse normal color and become black. If you can help me out will be great if you i will accept it also :) thank you.

        private void DrawPlayers()
    {
        try
        {
            foreach (var player in _playerInfo.Where(plr => plr != null))
            {
                if (player == null)
                {
                    File.WriteAllText("greske.txt", "player object is null.");
                    File.WriteAllText("greske.txt", _playerInfo.ToString());
                    foreach (var p in _playerInfo)
                    {
                        File.WriteAllText("greske.txt", $"Player {p.Profile?.Info?.Nickname ?? "'Unknown' is null"}: \n{p.ToString()}");
                    }
                    File.WriteAllText("greske.txt", _playerInfo.ToString());
                    return;
                }
                float distanceToObject = Vector3.Distance(Camera.main.transform.position, player.Transform.position);
                Vector3 playerBoundingVector = new Vector3(Camera.main.WorldToScreenPoint(player.Transform.position).x, Camera.main.WorldToScreenPoint(player.Transform.position).y, Camera.main.WorldToScreenPoint(player.Transform.position).z);

                if (distanceToObject <= _maxVueDistance && playerBoundingVector.z > 0.01 && playerBoundingVector.x > -5 && playerBoundingVector.y > -5 && playerBoundingVector.x < 1920 && playerBoundingVector.y < 1080)
                {
                    var playerHeadVector = new Vector3(
                        Camera.main.WorldToScreenPoint(player.PlayerBones.Head.position).x,
                        Camera.main.WorldToScreenPoint(player.PlayerBones.Head.position).y,
                        Camera.main.WorldToScreenPoint(player.PlayerBones.Head.position).z);

                    float boxVectorX = Camera.main.WorldToScreenPoint(player.Transform.position).x;
                    float boxVectorY = Camera.main.WorldToScreenPoint(player.PlayerBones.Head.position).y + 10f;
                    float boxHeight = Math.Abs(Camera.main.WorldToScreenPoint(player.PlayerBones.Head.position).y - Camera.main.WorldToScreenPoint(player.Transform.position).y) + 10f;
                    float boxWidth = boxHeight * 0.65f;

                    Color guiBackup = GUI.color;
                    var playerColor = GetPlayerColor(player.Side);
                    var isAi = player.Profile.Info.RegistrationDate <= 0;
                    var deadcolor = player.HealthController.IsAlive ? playerColor : Color.gray;

                    GUI.color = deadcolor;
                    Utility.DrawBox(boxVectorX - boxWidth / 2f, (float)Screen.height - boxVectorY, boxWidth, boxHeight, deadcolor);
                    Utility.DrawLine(new Vector2(playerHeadVector.x - 2f, (float)Screen.height - playerHeadVector.y), new Vector2(playerHeadVector.x + 2f, (float)Screen.height - playerHeadVector.y), deadcolor);
                    Utility.DrawLine(new Vector2(playerHeadVector.x, (float)Screen.height - playerHeadVector.y - 2f), new Vector2(playerHeadVector.x, (float)Screen.height - playerHeadVector.y + 2f), deadcolor);


                    var playerName = isAi ? "Bot" : player.Profile.Info.Nickname;
                    string playerDisplayName = player.HealthController.IsAlive ? playerName : playerName + " (Mrtav)";
                    string playerText = $"{playerDisplayName} [{(int)distanceToObject}]M";

                    var playerTextVector = GUI.skin.GetStyle(playerText).CalcSize(new GUIContent(playerText));
                    GUI.Label(new Rect(playerBoundingVector.x - playerTextVector.x / 2f, (float)Screen.height - boxVectorY - 20f, 300f, 50f), playerText);
                    GUI.color = guiBackup;
                }
            }
        }
        catch (Exception ex)
        {
            File.WriteAllText("greske.txt", ex.ToString());
        }
    }

0 Answers0