Пример #1
0
    private void Update()
    {
        if (!Active)
        {
            return;
        }
        if (pulling)
        {
            distance = Vector2.Distance(this.transform.position, player.transform.position) + 0.05f;
            if (distance > 0.1f)
            {
                direction           = this.transform.position - player.transform.position;
                player.outsideForce = (direction.normalized * forcePower / distance);
            }
            else
            {
                player.outsideForce = Vector2.zero;

                if (!trapped)
                {
                    trapped       = true;
                    player.active = false;
                    player.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
                    MemoryScene.ActivateMemoryScenePortal(memorySceneId);
                    Active = false;
                }
            }
        }
    }
Пример #2
0
    public static void ActivateMemoryScenePortal(int scnID)
    {
        MemoryScene activeScene = null;
        MemoryScene nextScene   = null;

        bool found = false;

        if (MemoryScenes != null)
        {
            for (int i = 0; i < MemoryScenes.Count; i++)
            {
                if (MemoryScenes[i] != null)
                {
                    if (MemoryScenes[i].id == scnID)
                    {
                        //MemoryScenes[i].gameObject.SetActive(true);
                        //GameHandler.Instance.playerCharacter.transform.position = MemoryScenes[i].startPosition.position;
                        //GameHandler.Instance.memoryCamera.transform.position = new Vector3(MemoryScenes[i].startPosition.position.x, MemoryScenes[i].startPosition.position.y, GameHandler.Instance.memoryCamera.transform.position.z);
                        //GameHandler.Instance.playerCharacter.GetComponent<CharacterController>().active = true;

                        nextScene = MemoryScenes[i];
                        found     = true;
                    }
                    else if (MemoryScenes[i].active)
                    {
                        activeScene = MemoryScenes[i];
                    }
                    //else MemoryScenes[i].gameObject.SetActive(false);
                }
            }
        }
        if (!found)
        {
            Debug.LogError("Scene Not Found");
            return;
        }

        if (nextScene != null /* && activeScene != null*/)
        {
            Debug.Log("Openning Scene\nNextScene " + nextScene.name + "\nActiveScene " + activeScene);
            Canvas nextSceneCanvas = nextScene.sceneEntryPortal.GetComponent <Canvas>();
            if (nextSceneCanvas != null)
            {
                GameHandler.Instance.InitPlayer(); // Temporary

                //Make Portal huge
                LeanTween.size(nextSceneCanvas.GetComponent <RectTransform>(), Vector2.one * 60, 5f).setOnComplete(() =>
                {
                    nextSceneCanvas.gameObject.SetActive(false);
                    GameHandler.Instance.playerCharacter.GetComponent <CharacterController>().active = true;
                    GameHandler.Instance.playerCharacter.GetComponent <CharacterController>().m_activationHandler = nextScene.sceneActivationHandler;
                    GameHandler.Instance.soundManager.PlayNext();


                    if (activeScene != null)
                    {
                        activeScene.gameObject.SetActive(false);
                    }

                    //Activate the things in next scene
                    if (nextScene.sceneObjects != null)
                    {
                        for (int i = 0; i < nextScene.sceneObjects.Count; i++)
                        {
                            nextScene.sceneObjects[i].SetActive(true);
                        }
                    }

                    nextScene.active   = true;
                    activeScene.active = false;
                });
            }
        }
        else
        {
            Debug.LogError("Active Scene :" + activeScene + " .. \nNext Scene " + nextScene);
        }
    }