Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Save shot used at the end of the previous scene to the next scene

Discussion in 'Scripting' started by BMM7, Nov 4, 2017.

  1. BMM7

    BMM7

    Joined:
    Sep 20, 2017
    Posts:
    54
    I am doing a shooting game where the player has 4 different types of shots (shot 1, shot 2, shot 3 and shot 4), and each shot has 4 levels of force, ie if the level of the shot is 1, the shot will have a size and start with a damage, if it is 2 the shot will be bigger and it will cause more damage.

    And every time I push a button, for example X button, i switch to shot 2, I pressed again and i switch to shot 3 and so on.
    If I change the scene and was using in the previous scene the shot 3 for example, how do I do that for the player to start the next level with the shot 3? That is, I want to start the next stage using the same shot I was using at the end of the previous stage.

    another thing, every time the player suffers damage, he lowers a strength level of the current shot he is using, for example the level of shot 2 is at 4, so I suffer a damage and the level lowers to 3, I suffer again a damage and the level goes down to 2.
    I also want to save this strength level shot for the next scene, how do I do all this? Can someone do this by script for me?
     
  2. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    What you're describing sounds like it could be solved with some simple playerprefs code, playerprefs allows you to carry data across a scene like you're asking for and since you're not asking for anything complicated like saving position and so on this should be fine for you.

    https://docs.unity3d.com/ScriptReference/PlayerPrefs.html



    In this situation you're going to have to work how to use playerprefs on your code and have the game save whatever shot, so specifically you would use playerprefs.setint to set your shots rather than what you're doing now.

    https://docs.unity3d.com/ScriptReference/PlayerPrefs.SetInt.html
     
    Last edited: Nov 24, 2017
    BMM7 likes this.
  3. BMM7

    BMM7

    Joined:
    Sep 20, 2017
    Posts:
    54
    Thank you Leth, I will try solve that with the playerprefs and I return later.
     
  4. BMM7

    BMM7

    Joined:
    Sep 20, 2017
    Posts:
    54
    I found the solution to what I wanted!
    Thank you!