Пример #1
0
 // Update is called once per frame
 void Update()
 {
     if (player)
     {
         if (active && player.GetTargetingSystem().GetTarget())
         {
             Vector3 targpos = player.GetTargetingSystem().GetTarget().position;
             Vector3 viewpos = Camera.main.WorldToViewportPoint(targpos);
             if (viewpos.x > 1 || viewpos.x < 0 || viewpos.y < 0 || viewpos.y > 1)
             {
                 spr.enabled      = true;
                 spr.sortingOrder = player.GetComponent <SpriteRenderer>().sortingOrder;
                 var x = (-player.transform.position + targpos);
                 x.z = 0;
                 float magcheck = Mathf.Max(viewpos.x, 1 - viewpos.x, viewpos.y, 1 - viewpos.y);
                 transform.localScale = new Vector3(1 / magcheck, 1 / magcheck, 1);
                 if (player.IsMoving() || init)
                 {
                     init = false;
                     transform.position = player.transform.position + x.normalized * 10;
                     // TODO: check condition for adding/subbing 90
                     transform.eulerAngles = new Vector3(0, 0, (Mathf.Rad2Deg * Mathf.Atan(x.y / x.x) - (x.x > 0 ? 90 : -90)));
                 }
             }
             else
             {
                 spr.enabled = false;
             }
         }
         else
         {
             spr.enabled = false;
         }
     }
 }
Пример #2
0
        public void Generate()
        {
            for (int i = 0; i < PlayerPoint.Length; i++)
            {
                GameObject tmpObject  = GameObject.Instantiate(Player, PlayerPoint[i], Quaternion.identity);
                PlayerCore playerCore = tmpObject.GetComponent <PlayerCore>();
                switch (i)
                {
                case (0):
                    playerCore.name     = "Player1";
                    playerCore.playerId = PlayerId.Player1;
                    playerCore.GetComponent <Renderer>().material.color = PlayerIdExtensions.ToColor(PlayerId.Player1);
                    toPleyerObject.Player1 = tmpObject;
                    break;

                case (1):
                    playerCore.name     = "Player2";
                    playerCore.playerId = PlayerId.Player2;
                    playerCore.GetComponent <Renderer>().material.color = PlayerIdExtensions.ToColor(PlayerId.Player2);
                    toPleyerObject.Player2 = tmpObject;
                    break;

                case (2):
                    playerCore.name     = "Player3";
                    playerCore.playerId = PlayerId.Player3;
                    playerCore.GetComponent <Renderer>().material.color = PlayerIdExtensions.ToColor(PlayerId.Player3);
                    toPleyerObject.Player3 = tmpObject;
                    break;

                case (3):
                    playerCore.name     = "Player4";
                    playerCore.playerId = PlayerId.Player4;
                    playerCore.GetComponent <Renderer>().material.color = PlayerIdExtensions.ToColor(PlayerId.Player4);
                    toPleyerObject.Player4 = tmpObject;
                    break;
                }
                tmpObject.SetActive(false);
            }
        }
Пример #3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab) && cooldown == 0)
        {
            menuActive = !menuActive;
            if (menuActive)
            {
                //HUD
                UI_HUD.i.GetComponent <CanvasGroup>().alpha = 0;

                //Update Elements
                MenuRequestAbilitiesInfo();
                playerCore.GetComponent <PlayerInventory>().CmdFindItemsInProximity();
                MenuInventoryRequest();

                //Root
                StartCoroutine(Fade(1));
                root.blocksRaycasts = true;
                root.interactable   = true;

                //UI
                UI_State.ChangeState(true);
            }
            else
            {
                //HUD
                UI_HUD.i.GetComponent <CanvasGroup>().alpha = 1;

                //Root
                root.alpha          = 0;
                root.blocksRaycasts = false;
                root.interactable   = false;

                //Character
                characterMenu.alpha          = 0;
                characterMenu.blocksRaycasts = false;
                characterMenu.interactable   = false;

                //Ability
                abilityMenu.alpha          = 0;
                abilityMenu.blocksRaycasts = false;
                abilityMenu.interactable   = false;

                //UI
                UI_State.ChangeState(false);
            }

            //Apply cooldown
            cooldown = 0.35f;
        }

        if (menuActive)
        {
            //Proximity Update
            Collider[] proximityItems = Physics.OverlapSphere(playerCore.transform.position, 1.5f, itemLayerMask);
            if (savedProximity.Length != proximityItems.Length)
            {
                playerCore.GetComponent <PlayerInventory>().CmdFindItemsInProximity();
            }
        }

        cooldown = Mathf.Clamp(cooldown - Time.deltaTime, 0, 0.6f);
    }
Пример #4
0
        IEnumerator pathPlayer(PlayerCore player)
        {
            player.SetIsInteracting(false);
            PathData.Node current = GetNode(0);

            while (current != null)
            {
                Vector2 delta = current.position - (Vector2)player.transform.position - player.GetComponent <Rigidbody2D>().velocity *Time.fixedDeltaTime;
                player.MoveCraft(delta.normalized);
                if (delta.sqrMagnitude < PathAI.minDist)
                {
                    if (current.children.Count > 0)
                    {
                        int next = Random.Range(0, current.children.Count);
                        current = GetNode(current.children[next]);
                    }
                    else
                    {
                        current = null;
                    }
                }

                yield return(null);
            }

            player.SetIsInteracting(true);

            if (!asynchronous)
            {
                continueTraversing();
            }
        }