im at school atm scripting this in a text document, so there is probably some errors since im not that good at scripting yet, but i want to be able to finish a battle and resume the game where I left off at. heres what i have so far :
private float RC;
public bool RandEncounter = true;
public bool inBattle = false
function update(){
if (RandEncounter){
if(get.Axis("L_U D"){
RC = random.range(1, 100)
if(RC >= 47){
if (RC <= 75){
inBattle = true;
}
}
}
}
if(inBattle){
}
and since the random is being generated in “function Update” does it constantly create new numbers?
before i load my battle level (which is gonna be randomly generated) i need to cache the location of the player so after the battle, gameplay resumes where it left off, how would i do this?
Depending on how you are storing the player’s transform in the game world (not the world position, though it may be synonymous with the world position), you can just create a new member variable in the player class, which can be a Vector3 if all you want to do is store the player’s position and not their orientation, etc. This member variable would be called something like “PreCombatPosition” and when you enter your combat scene, you store the player’s current position in “PreCombatPosition” and then, when you exit the combat scene, you restore the player’s position from the same variable. One variable declaration and most likely two lines of code.
I’m not sure how I would even do that though, I sort of figured that it would have to deal with vector3 but I have no clue ho to do any of what you described. Could you please give me an example of what you mean?
In your concept, what is the battlefield? is it just a scene off to the left, or is it a whole new level that you load?
To keep basic info, you will need a GameController to help keep all the things in line. This object should use the DontDestroyOnLoad feature that allows it to be kept in the scene. In this controller, you keep current player position or whatever you need to to keep your game in line.
If you fight is off tot he “left”, but in the same scene, you will want the GameController to keep the player position, and the fact that the actual game is paused while this is going on. Your game scripts do the fight, when it is done, the game script is then un paused and you are put back at the position you were.
In a fight that is a new level, the persistant GameController waits for the new level to load, and unload, then resumes it’s actions.
A handy piece of script:
function Awake(){
if(GameObject.Find("GameController")){
Destroy(gameObject);
return;
}
gameObject.name="GameController";
DontDestroyOnLoad(gameObject);
}
All you would have to do is NOT name the object GameController. This way, when the first level loads again, the new game controller would destroy it’s self because it already exists.
im gonna be loading a completely new level thats randomly generated to an extent. so is that script a new script entirely? and what does it go on, the playable character?
That script there will probably go on the game controller. Imagine the GameController or whatever Game Object controls the game, is global and can never be destroyed until you quit the game, so it goes everywhere to every new scene that’s loaded.
Finding a way to do this may be a different matter, but maybe the DontDestroyOnLoad may be something you want to look at.
I also recommend that you may want to try and keep the same battle on the same scene, by simply moving the Camera to another position on the scene, this way you do not have to always store states when you go into a battle, and then restore the states when you come out of battle, the reason I am suggesting this is because you are going to have to keep track of every dynamic object in that scene before you go into battle, enemy positions, enemy states etc. You’re probably going to increase your work load in the end if you decide to jump from scene to scene, however it is always completely up to you.
thanks for your advice, but im working an a new type or FPS RPG. and thats how the battle system is gonna be. its something i havent seen before, random battles and when your battling its like a CoD battle, but every battle scene is gonna be different with new ways to hide and stuff like that.
~edit~
getting a new error when testing my encounter script
“Cannot implicitly convert type float' to bool’”
Personally I think you are way out of your depth on this entire project and should start with something simpler. Your error in the float to bool conversion is to do with the fact you are reading the input axis and immediately testing the return float value. You will want to test the return value against another value to make it a float, such as non-zero.