示例#1
0
        void Update()
        {
            // Store the input variable.  We multiply by 10 as the actual increments by default are 0.1f, if you wish to alter these yourself make sure to check out the Edit -> Project Settings -> Input -> Mouse ScrollWheel.
            axisNum = Input.GetAxisRaw("Mouse ScrollWheel") * 10f;
            // IF the input is not the middle mouse wheel OR we have a coroutine already running OR we dont have a player in the scene.
            // (Normally all mouses these days have a middle button so just code for that, if someone really doesnt have a middle mouse button then this isnt on you, it's on them at this point in time with technology.
            // We stop coding for ancient devices after a while or the most simple scripts would be loaded with a lot of crap we dont need to deal with which destroys time and time is the most valuable asset we have.)
            if (axisNum == 0f || isRunning || Character_Helper.GetPlayer() == null)
            {
                // No zoom so we do nothing.
                return;
            }
            // Get the amount to move based on the axisNum and the zoomAmount;
            float amountToMove = axisNum * zoomAmount;

            // Lets get our destination of where we want to move.
            destinationOrthoSize = referenceSize - amountToMove;
            // Now lets check if we are in the boundaries.
            // IF our destinationOrthoSize is bigger than our maxZoom we want,
            // ELSE IF our destinationOrthoSize is less than our minZoom we want,
            if (destinationOrthoSize >= maxZoom)
            {
                // Set the destinationOrthoSize to be our maxZoom.
                destinationOrthoSize = maxZoom;
            }
            else if (destinationOrthoSize <= minZoom)
            {
                // Set the destinationOrthoSize to be our minZoom.
                destinationOrthoSize = minZoom;
            }
        }
示例#2
0
 void OnTriggerExit2D(Collider2D coll)
 {
     // IF this is the player.
     if (coll.gameObject == Character_Helper.GetPlayer())
     {
         // IF we want to destroy the spawned gameobject when we leave this section.
         if (destroyOnExit)
         {
             // Loop through all of our Monster_Spawners.
             for (int i = 0; i < mobSpawner.Length; i++)
             {
                 // Destroy all the monsters.
                 mobSpawner [i].DestroyAllMonsters();
             }
             // We leave.
             return;
         }
         // Loop through all of our Monster_Spawners.
         for (int i = 0; i < mobSpawner.Length; i++)
         {
             // Deactivate the monsters left in this area.
             mobSpawner [i].SetMonstersActiveness(false);
         }
     }
 }
        /// <summary>
        /// We check to see whenever the player is spawned in the scene and then we act.
        /// </summary>
        void Update()
        {
            // IF the player gameobject is null.
            if (playerGO == null)
            {
                // Get the player GameObject.
                playerGO = Character_Helper.GetPlayer();
                return;
            }
            // IF the players reference to its transform is null.
            if (playerTransform == null)
            {
                // Grab the transform.
                playerTransform = playerGO.transform;
            }

            // IF we have not set our bounds yet.
            if (!isBounds)
            {
                // Leave as we have no boundaries so we do not know wtf to do in terms of any restriction on how this camera mechanic is supposed to work
                return;
            }
            // IF we are currently in a cutscene.
            if (isCutScene)
            {
                // We are in a cutscene so we do not care about how this camera operates as in a cutscene we are manually controlling the camera.
                return;
            }
            // In-case we have any sort of zoom feature along with boundaries we def need to refresh our cameras width and height.
            RefreshBounds();
            // We passed all of our prequisites so lets clamp values between the bounds.
            camX = Mathf.Clamp(playerTransform.position.x + (rightUILength - leftUILength) / 2f, finalLeftBound - leftUILength, finalRightBound - rightUILength);
            camY = Mathf.Clamp(playerTransform.position.y + (topUILength - botUILength) / 2f, finalBottomBound - botUILength, finalTopBound + topUILength);
        }
 /// <summary>
 /// We check to see whenever the player is spawned in the scene and then we act.
 /// </summary>
 void Update()
 {
     // IF the player gameobject is null.
     if (playerGO == null)
     {
         // Get the player GameObject.
         playerGO = Character_Helper.GetPlayer();
         return;
     }
     // IF the players reference to its transform is null.
     if (playerTransform == null)
     {
         // Grab the transform.
         playerTransform = playerGO.transform;
     }
     // IF the bounds have been set and we are not in a cutscene.
     if (isBounds && !isCutScene)
     {
         // Incase we have any sort of zoom feature along with boundaries we def need to refresh our cameras width and height.
         RefreshBounds();
         // Clamp values between the bounds.
         camX = Mathf.Clamp(playerTransform.position.x + (rightUILength - leftUILength) / 2f, finalLeftBound - leftUILength, finalRightBound + rightUILength);
         camY = Mathf.Clamp(playerTransform.position.y + (topUILength - botUILength) / 2f, finalBottomBound - botUILength, finalTopBound + topUILength);
     }
 }
示例#5
0
 void OnTriggerEnter2D(Collider2D coll)
 {
     // IF this is the player.
     if (coll.gameObject == Character_Helper.GetPlayer())
     {
         // Set to true for spawning.
         timeToSpawn = true;
     }
 }
示例#6
0
 void OnCollisionEnter2D(Collision2D coll)
 {
     // IF the colliding GameObject is the player.
     if (coll.gameObject == Character_Helper.GetPlayer())
     {
         // We are close enough for when we use the KeyCode it will spawn monsters.
         isCloseEnough = true;
     }
 }
示例#7
0
 void OnTriggerExit2D(Collider2D coll)
 {
     // IF the colliding GameObject is the player.
     if (coll.gameObject == Character_Helper.GetPlayer())
     {
         // We are NOT close enough for when we use the KeyCode it will spawn monsters.
         isCloseEnough = false;
     }
 }
示例#8
0
        /// <summary>
        /// Tosses the item out of inventory.
        /// </summary>
        public void TossItemOutOfInventory(string itemTitle, int slotNumber, int amount)
        {
            // Spawn the item from it being thrown out of the inventory.
            GameObject goItem = Grid_Helper.helper.SpawnObject(Grid_Helper.setup.GetGameObjectPrefab(itemTitle), Character_Helper.GetPlayer().transform.position, Quaternion.identity, Character_Helper.GetPlayer(), radius);

            // Store the amount that was tossed out.
            goItem.GetComponent <Item_GameObject> ().amount = amount;
            // Launch the item in a random direction.
            Grid_Helper.helper.LaunchAwayFromPosition(goItem, Character_Helper.GetPlayer().transform.position, forcePower);
        }
示例#9
0
 void OnTriggerEnter2D(Collider2D coll)
 {
     // IF the colliding GameObject is NOT the player.
     if (coll.gameObject != Character_Helper.GetPlayer())
     {
         // We leave.
         return;
     }
     // Lets change our scene.
     StartSceneVisualTransition();
 }
 void Start()
 {
     // Get the player GameObject.
     playerGO = Character_Helper.GetPlayer();
     // IF the player GameObject is null.
     if (playerGO == null)
     {
         // IF after searching and no player at the Start, then we can assume this scene doesnt have a player in it and we will not control the positioning of this Camera from here.
         return;
     }
     // Grab the transform.
     playerTransform = playerGO.transform;
 }
示例#11
0
 void LateUpdate()
 {
     // IF the input is not the middle mouse wheel OR there is a zoom already happening OR there isnt a player in the scene.
     if (axisNum == 0 || isRunning || Character_Helper.GetPlayer() == null)
     {
         // Do nothing as we didn't zoom.
         return;
     }
     // We need to stop all of our current zooming as we have a new destination for our Orthographic Size.
     StopAllCoroutines();
     // Start the coroutine which zooms.
     StartCoroutine(ZoomTime(cam.orthographicSize, destinationOrthoSize, zoomTime));
 }
 // Incase you want to have a 1 use camera we need to set defaults on a scene change and set up the boundary variables before we track the player.
 void OnLoadedLevel(Scene scene, LoadSceneMode mode)
 {
     // Set defaults.
     isBounds = false;
     // Get the player GameObject.
     playerGO = Character_Helper.GetPlayer();
     // IF we have a player to get when changing the scene.
     if (playerGO == null)
     {
         return;
     }
     // Grab the transform of the player.
     playerTransform = playerGO.transform;
 }
 // Incase you want to have a 1 use camera we need to set defaults on a scene change and set up the boundary variables before we track the player.
 void OnLoadedLevel(Scene scene, LoadSceneMode mode)
 {
     // Set defaults.
     isBounds = false;
     // Get the player GameObject.
     playerGO = Character_Helper.GetPlayer();
     // IF the player does not exists... yet.
     if (playerGO == null)
     {
         return;
     }
     // Cache the transform.
     playerTransform = playerGO.transform;
 }
 void Start()
 {
     // Need to check if the playeris inside the bounds.
     if (IsPlayerInBounds(Character_Helper.GetPlayer().transform.position))
     {
         // IF the Follow_Slide_Camera exists.
         if (cameraFollowSlide != null)
         {
             // Set the new boundaries.
             SetNewBounds();
             return;
         }
     }
 }
示例#15
0
 /// <summary>
 /// Currently in the Demo we save valuable information when we transfer to another scene only as this is to prevent any unwanted hiccups while playing.
 /// When you enter an area that is where you will start if your game were to crash or if the player wants to stop playing and come back later
 /// (Remember this is only in the demo, you can have your save setup however you want).
 ///
 /// This only differs by loading the scene with LoadSceneAsync as it allows for a smoother transfer of scene loading.
 /// If you have some sort of animation happening like a twirling/spinning camera while you want to change scenes like in some Turn-Based games like Final Fantasy.
 /// </summary>
 public void ChangeSceneAsync(string newScene, int spawnLocation)
 {
     // IF there is a player.
     if (Character_Helper.GetPlayer() != null)
     {
         // Save the player setup.
         SavePlayerSetup();
     }
     // Save any scene based information.
     SaveSceneSetup(newScene, spawnLocation);
     // Save the player prefs to disk.
     PlayerPrefs.Save();
     // Change the scene in a more smooth manner.
     SceneManager.LoadSceneAsync(newScene);
 }
示例#16
0
 /// <summary>
 /// Displays the dialogue panel.
 /// </summary>
 public void DisplayDialoguePanel(bool display)
 {
     // Display the dialogue panel based on 'display'.
     dialoguePanel.SetActive(display);
     // IF we are displaying the dialogue panel,
     // ELSE we are removing the dialogue panel.
     if (display)
     {
         // Lets Setup.
         SendCharacterInfo(GetClosestDialogue().gameObject, false, true, Character_Helper.GetPlayer());
     }
     else
     {
         // Reset to start standards.
         GetClosestDialogue().ResetDialogue();
         ResetDialogue();
     }
 }
示例#17
0
 void Start()
 {
     // Get the player GameObject.
     playerGO = Character_Helper.GetPlayer();
     // IF the player GameObject is null.
     if (playerGO == null)
     {
         // IF after searching and no player at the Start, then we can assume this scene doesnt have a player in it and we will not control the positioning of this Camera from here.
         return;
     }
     // Grab the transform.
     playerTransform = playerGO.transform;
     // Set Initial Settings.
     SetLengthsAndOffsets();
     // Initially position in the bottom left tile of one of your slide areas so we can get a proper start position and smooth slide transitions when going to another area (not another scene but just the same scene but the area next to it).
     PositionCamera();
     // Set the camera up where it is supposed to start since we have found the player.
     AlignCamera();
 }
示例#18
0
 /// <summary>
 /// Spawns the player.
 /// </summary>
 private void SpawnPlayer()
 {
     // IF we have a player to spawn.
     if (Grid_Helper.setup.player != null)
     {
         // IF the player is already spawned,
         // ELSE the player is not spawned and needs to be and will be positioned accordingly.
         if (Character_Helper.GetPlayer() != null)
         {
             // Move this player to the new location.
             Character_Helper.GetPlayer().transform.position = sceneSpawnLocations [Grid_Helper.setup.GetSceneSpawnLocation()].position;
         }
         else
         {
             // Create this player at the appropriate location.
             Instantiate(Grid_Helper.setup.player, sceneSpawnLocations [Grid_Helper.setup.GetSceneSpawnLocation()].position, Quaternion.identity);
         }
     }
 }
示例#19
0
        // Make the text type out based on the text speed.
        public static IEnumerator TypeText(Text txt, float pauseTime, string dialogue, AudioClip typeSound)
        {
            // IF we have a null text.
            if (txt == null)
            {
                // We leave.
                yield break;
            }
            // Set a blank text.
            txt.text = "";
            // Loop and type out the text.
            for (int i = 0; i <= dialogue.Length; i++)
            {
                txt.text = dialogue.Substring(0, i);
                Grid_Helper.soundManager.PlaySound(typeSound, Character_Helper.GetPlayer().transform.position, 1f, 1f);
                yield return(new WaitForSeconds(pauseTime));

                yield return(null);
            }
        }
示例#20
0
 void Update()
 {
     // IF we didnt have a target.
     if (target == null)
     {
         // IF we want the player AND a Player exists.
         if (targetPlayer && Character_Helper.GetPlayer() != null)
         {
             // Set the player transfer.
             target = Character_Helper.GetPlayer().transform;
             // Leave.
             return;
         }
     }
     else
     {
         // Find a path.
         PathRequestManager.RequestPath((Vector2)transform.position, (Vector2)target.position, OnPathFound);
     }
 }
示例#21
0
        // Incase you want to have a 1 use camera we need to set defaults on a scene change and set up the boundary variables before we track the player.
        void OnLoadedLevel(Scene scene, LoadSceneMode mode)
        {
            // Call what normally would happen if this camera was running its code for the first time.
            SetIsPanning(false);

            // Set Initial Settings.
            SetLengthsAndOffsets();
            // Get the player GameObject.
            playerGO = Character_Helper.GetPlayer();
            // IF the player does not exists... yet.
            if (playerGO == null)
            {
                return;
            }
            // Cache the transform.
            playerTransform = playerGO.transform;
            // Initially position in the bottom left tile of one of your slide areas so we can get a proper start position and smooth slide transitions when going to another area (not another scene but just the same scene but the area next to it).
            PositionCamera();
            // Set the camera up where it is supposed to start since we have found the player.
            AlignCamera();
        }
示例#22
0
 void Update()
 {
     // IF the user hits The Options Key.
     if (Input.GetKeyUp(optionsKey))
     {
         // Currently we only want to show the options when we have the player created and in the scene.  Think of scenes where there wont be a player... Main menu, Credits, any type of cenamtic... These types of scenes we either do not want
         // to show the options menu or we have a button somewhere in the scene to bring it up (Main Menu).
         if (Character_Helper.GetPlayer() == null)
         {
             // No player no options menu.
             return;
         }
         // IF the panel is not showing then display it.
         // ELSE the panel is showing then remove it.
         if (!optionsPanel.activeInHierarchy)
         {
             OptionsDisplay(true);
         }
         else
         {
             OptionsDisplay(false);
         }
     }
 }
示例#23
0
 void Update()
 {
     // IF the player GameObject is null.
     if (playerGO == null)
     {
         // Get the player GameObject.
         playerGO = Character_Helper.GetPlayer();
         return;
     }
     // IF the players reference to its transform is null.
     if (playerTransform == null)
     {
         // Grab the transform.
         playerTransform = playerGO.transform;
     }
     // IF we are in a cutscene.
     if (isCutScene)
     {
         // Do nothing with the camera .
         return;
     }
     // Detect IF we are at the edges of the Camera to Pan.
     CameraEdgeDetection();
 }