Vector3 getRandomGo()
    {
        if (UnitZ.NetworkGameplay)
        {
            Vector3 pos = positionTemp + new Vector3(Random.Range(-PatrolRange, PatrolRange), 0, Random.Range(-PatrolRange, PatrolRange));
            BattleRoyaleGamePlay gameplay = UnitZ.NetworkGameplay.GetComponent <BattleRoyaleGamePlay>();
            if (gameplay != null)
            {
                Vector2 safeArea = (Random.insideUnitCircle * gameplay.Radius);
                pos = gameplay.CentreArea + new Vector3(safeArea.x, 0, safeArea.y);
                RaycastHit hit;
                if (Physics.Raycast(pos + (Vector3.up * 100), -Vector3.up, out hit))
                {
                    pos = hit.point;
                }
            }
            else
            {
                if (ObjectiveTarget)
                {
                    pos = ObjectiveTarget.transform.position + new Vector3(Random.Range(-PatrolRange, PatrolRange), 0, Random.Range(-PatrolRange, PatrolRange));
                }
                else
                {
                    pos = positionTemp + new Vector3(Random.Range(-PatrolRange, PatrolRange), 0, Random.Range(-PatrolRange, PatrolRange));
                }
            }
            positionMoveTmp = pos;
            return(pos);
        }
        else
        {
            Vector3 pos = positionTemp + new Vector3(Random.Range(-PatrolRange, PatrolRange), 0, Random.Range(-PatrolRange, PatrolRange));
            if (ObjectiveTarget)
            {
                pos = ObjectiveTarget.transform.position + new Vector3(Random.Range(-PatrolRange, PatrolRange), 0, Random.Range(-PatrolRange, PatrolRange));
            }

            positionMoveTmp = pos;
            return(pos);
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (UnitZ.NetworkGameplay != null)
        {
            BattleRoyaleGamePlay gameplay = UnitZ.NetworkGameplay.GetComponent <BattleRoyaleGamePlay>();
            if (gameplay != null)
            {
                if (TimeText != null)
                {
                    float timer   = gameplay.GetTimeToNextArea;
                    float minutes = Mathf.Floor(timer / 60);
                    float seconds = Mathf.RoundToInt(timer % 60);
                    TimeText.text = minutes + ":" + seconds;
                }
                if (SafeArea)
                {
                    if (gameplay.safeArea != null)
                    {
                        SafeArea.anchoredPosition = WorldPositionToMap(new Vector2(MiniMap.rect.width, MiniMap.rect.height), gameplay.safeArea.transform.position);
                        Vector2 newsize = new Vector2(resize(MiniMap.rect.width, WorldRealSize.x) * gameplay.safeArea.transform.localScale.x, resize(MiniMap.rect.height, WorldRealSize.y) * gameplay.safeArea.transform.localScale.z);
                        SafeArea.sizeDelta = newsize;
                    }
                    SafeArea.gameObject.SetActive(gameplay.safeArea && gameplay.safeArea.activeSelf);
                }

                if (DeadArea)
                {
                    if (gameplay.lastDeadArea != null)
                    {
                        DeadArea.anchoredPosition = WorldPositionToMap(new Vector2(MiniMap.rect.width, MiniMap.rect.height), gameplay.lastDeadArea.transform.position);
                        Vector2 newsize = new Vector2(resize(MiniMap.rect.width, WorldRealSize.x) * gameplay.lastDeadArea.transform.localScale.x, resize(MiniMap.rect.height, WorldRealSize.y) * gameplay.lastDeadArea.transform.localScale.z);
                        DeadArea.sizeDelta = newsize;
                    }
                    DeadArea.gameObject.SetActive(gameplay.lastDeadArea && gameplay.lastDeadArea.activeSelf);
                }
            }
            else
            {
                if (SafeArea)
                {
                    SafeArea.gameObject.SetActive(false);
                }
                if (DeadArea)
                {
                    DeadArea.gameObject.SetActive(false);
                }
            }

            if (Player == null && UnitZ.playerManager && UnitZ.playerManager.PlayingCharacter)
            {
                Player = UnitZ.playerManager.PlayingCharacter.gameObject;
            }

            if (MiniMap != null && PlayerIndicator != null && Player != null)
            {
                if (!FixedPlayer)
                {
                    Vector2 position = WorldPositionToMap(new Vector2(MiniMap.rect.width, MiniMap.rect.height), Player.transform.position);
                    PlayerIndicator.anchoredPosition = position;
                    Quaternion rota = PlayerIndicator.rotation;
                    rota.eulerAngles         = new Vector3(rota.eulerAngles.x, rota.eulerAngles.y, -Player.transform.rotation.eulerAngles.y);
                    PlayerIndicator.rotation = rota;
                }
                else
                {
                    MiniMap.anchoredPosition         = WorldPositionToMap(new Vector2(-MiniMap.rect.width, -MiniMap.rect.height), Player.transform.position);
                    PlayerIndicator.anchoredPosition = Vector2.zero;
                    Quaternion rota = PlayerIndicator.rotation;
                    rota.eulerAngles         = new Vector3(rota.eulerAngles.x, rota.eulerAngles.y, -Player.transform.rotation.eulerAngles.y);
                    PlayerIndicator.rotation = rota;
                }
            }
        }
    }