Starting to add some of the objects / traps in.
[img]http://i.imgur.com/EYJEKF7.gif[/img]
Hey, here's a noob question. How do I make states persist between scenes?
Say I have a few different scenes for different parts of the gameplay. Like for example I have the main screen that would ask something like "What do you want to do today?" and if you click "Mow the lawn" it takes you to a mow the lawn scene. That much I know I can handle - let's say you get 20 bucks for mowing the lawn - how do I make that persist across the entire program? Savefile somewhere?
[QUOTE=Protocol7;45272033]Hey, here's a noob question. How do I make states persist between scenes?[/QUOTE]
Couple different ways. You could do [url=http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html[/url] DontDestroyOnLoad[/url], basically have an object that wont be destroyed between scenes that has the script with your variables. You could also go with the [url=http://docs.unity3d.com/ScriptReference/PlayerPrefs.html]PlayerPrefs[/url] to store your variables then load them using Start() from an script in that scene.
[editline]2nd July 2014[/editline]
Also have a look at [url=http://unity3d.com/learn/tutorials/modules/intermediate/scripting/statics[/url]Static Variables[/url]
So DontDestroyOnLoad keeps objects in memory, and PlayerPrefs is sort of that with a way to save to disk?
[editline]2nd July 2014[/editline]
Also no matter what I do I can't get Intellisense to work with Unity suggestions. I've tried "Sync MonoDevelop Project" in the settings but I don't think that will work for obvious reasons...
Yeah, PlayerPrefs is a really basic way of storing data for when the app is closed, and DontDestroy just keeps the object but wont retain the information if you exit the program.
There are options and addons available for saving / storing lots of data, but PlayerPrefs is fine for a basic amount of data.
All I really need to retain is a bunch of numbers, so both will be fine. Thanks!
I would use static variables in that case.
So you might have:
[code]
public class GameState
{
public static int Money = 0;
public static void LoadGame()
{
Money = PlayerPrefs.GetInt( "Save.Money" );
}
public static void SaveGame()
{
PlayerPrefs.SetInt( "Save.Money", Money );
PlayerPrefs.Save();
}
}
[/code]
This on the one hand insulates you from PlayerPrefs (in case you decide you would rather use custom serialized save files, for instance), and on the other hand allows you to somewhat easily add more data - just stuff that data as a static value in the GameState class, and add logic for saving/loading it.
I might try to like just dump a JSON blob out to a file. I'm very familiar with that in the .NET world and would prefer that.
[QUOTE=Protocol7;45272077]Also no matter what I do I can't get Intellisense to work with Unity suggestions. I've tried "Sync MonoDevelop Project" in the settings but I don't think that will work for obvious reasons...[/QUOTE]
Here's how to get VS working for your project: [URL]http://docs.unity3d.com/Manual/VisualStudioIntegration.html[/URL]
[QUOTE=Pelf;45272326]Here's how to get VS working for your project: [URL]http://docs.unity3d.com/Manual/VisualStudioIntegration.html[/URL][/QUOTE]
Before I reformatted my computer, unity would never properly open up in visual studio. No matter what I did, it would open monodevelop and I would have to open the project in visual studio manually, even uninstalling mono develop it would try to open it, and just crash out.
After the reformat and reinstalling unity, I unticked monodevelop installation, and it used visual studio by default, so much easier...
First of all, new to Unity, so sorry about my stupidness if I'm doing something absolutely stupid here, but why the hell doesn't this shrink the scale of the object through 120 seconds? The debug shows that it goes to the "to" size (0.5f) right away.
[code]
void Start () {
Debug.Log (battleCircle.localScale);
Vector3 size = new Vector3 (Mathf.Lerp (battleCircle.localScale.x, .5f, 120 * Time.deltaTime), 0.2f, Mathf.Lerp (battleCircle.localScale.z, .5f, 120 * Time.deltaTime));
battleCircle.localScale = size;
Debug.Log (battleCircle.localScale);
}
[/code]
[QUOTE=Persious;45273523]First of all, new to Unity, so sorry about my stupidness if I'm doing something absolutely stupid here, but why the hell doesn't this shrink the scale of the object through 120 seconds? The debug shows that it goes to the "to" size (0.5f) right away.
[code]
void Start () {
Debug.Log (battleCircle.localScale);
Vector3 size = new Vector3 (Mathf.Lerp (battleCircle.localScale.x, .5f, 120 * Time.deltaTime), 0.2f, Mathf.Lerp (battleCircle.localScale.z, .5f, 120 * Time.deltaTime));
battleCircle.localScale = size;
Debug.Log (battleCircle.localScale);
}
[/code][/QUOTE]
A lerp, quite simply, returns a number between A and B, depending on variable C (a number between 0 and 1) ( [URL]http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html[/URL] ).
For example,
[code]
Mathf.Lerp( 5, 10, 0.5f );
[/code]
Would return 7.5. This is because halfway between 5 and 10 is 7.5.
120 * Time.deltaTime would return god-knows-what, but probably a number higher than one. Therefore it returns variable B completely, which is .5f in your case.
What you would like to do is move it to an update loop and do something like this
[code]
int SecondsToScale = 120;
void Update() {
timer += Time.deltaTime;
float scaleTimer = timer / SecondsToScale;
Vector3 size = new Vector3( Mathf.Lerp( battleCircle.localScale.x, 0.5f, scaleTimer ) ...
}
[/code]
You increment the timer by the delta time, divide the timer by the seconds it's supposed to take to scale, and use that to lerp between the two scale values.
That worked, it scales and does exactly what I wanted, but the seconds are way off, it's scaling really fast?
EDIT: fuck me page king, and nothing to show :<
If you want a lerp that takes a specific amount of time to complete, you will want to keep track of the original start and end values.
For instance, this:
[code]
myValue = Mathf.Lerp( myValue, endValue, someLerpFactor );
[/code]
Won't interpolate in constant time. However, this would work:
[code]
// before starting the lerp...
var startValue = myValue;
// during the update...
myValue = Mathf.Lerp( startValue, endValue, someLerpFactor );
[/code]
This is biting my ass, so what I've got this far, but I can't seem to get this to work.
[code]
public Transform battleCircle;
public int SecondsToScale = 120;
public float sizeOfBattleGround = .5f;
private float timer;
private Vector3 myValue;
void Start() {
myValue = battleCircle.localScale;
}
void Update() {
timer += Time.deltaTime;
float scaleTimer = timer / SecondsToScale;
Vector3 startValue = myValue;
myValue = new Vector3 (Mathf.Lerp (startValue.x, sizeOfBattleGround, scaleTimer), 0.2f, Mathf.Lerp(startValue.z, sizeOfBattleGround, scaleTimer));
battleCircle.localScale = myValue;
Debug.Log (battleCircle.localScale);
}
[/code]
That's not what I meant.
startValue has to be assigned, once, prior to the lerp, not every frame.
[code]
public Transform battleCircle;
public int SecondsToScale = 120;
public float sizeOfBattleGround = .5f;
private float timer;
private Vector3 startValue;
void Start() {
startValue = battleCircle.localScale;
}
void Update() {
timer += Time.deltaTime;
float scaleTimer = timer / SecondsToScale;
var scale = new Vector3 (Mathf.Lerp (startValue.x, sizeOfBattleGround, scaleTimer), 0.2f, Mathf.Lerp(startValue.z, sizeOfBattleGround, scaleTimer));
battleCircle.localScale = scale;
Debug.Log (battleCircle.localScale);
}
[/code]
Ooh, I see, that was pretty obvious. It works now.. Thank you!
I'm working on my level editor some more and I'm trying to neaten up my code to make adding features easier and because it's really bloated. One thing I started doing was to separate Input and GUI code into two separate scripts that inherit common fields/methods from a base script. I have some variables though (state variables, current selected object, etc) that need to be the same between the two. in some cases, like the current selected object, both scripts can modify the variable.
My question is; what's a good way to keep these variables synced? Static variables in the base class? Some other way?
What about having some LevelEditorManager script which keeps track of shared state? Maybe as static variables?
[QUOTE=Jcorp;45267817]I'm perhaps a day late, but I'd like to have a go at talking about the "Unity" look. While I thoroughly agree that it is the result of either not bothering or not having enough time to polish the visuals of what you have, it's also important to have some kind of "artistic style" to head towards and polish in the first place, something that many people seemingly have trouble with - myself included.
It seems to be that, as most people who delve into indie games (or use unity) are programmers, the majority of us don't have any artistic experience, or we don't deem our projects to be worth getting someone who has artistic experience on board. This tends to cause budding game devs using unity to just stick with the presets, as it's the only thing they really have at their disposal. They don't try to change or add things in any attempt to get a specific "look", which makes everything look the same.
Here's what I've been doing, which ties into it a bit. As I'm not much of an artist, and I only have access to art-based help occasionally, I decided to make something that was incredibly low-poly; perhaps cliché, but it's what I had to do. I then decided I wanted something very barren and lifeless - something that is changed over the course of the game - so I decided to turn everything very orange and slightly red, with some environment stuff plastered around the place to vary things up (rocks with different shades of orange, quite colourful man-made buildings, occasional trees, and other stuff I haven't made up yet). This has turned it into something that, while not looking great (IMHO), at least slightly differentiates it from the rest of the Unity crowd.
Additionally, here's a laggy video of what I've done with it recently - adding AO to some props and a new mining drill.
*video*[/QUOTE]
How did you make the terrain and the models?
I doubt you used unity's terrain system.
Did you make everything in blender or ProBuilder?
UnityVS is gonna be free soon. Microsoft acquired SyntaxTree. It's not up yet, but according to the article, it's gonna be free to download soon
[url]http://blogs.msdn.com/b/somasegar/archive/2014/07/02/microsoft-acquires-syntaxtree-creator-of-unityvs-plugin-for-visual-studio.aspx[/url]
I'm quite happy about that. UnityVS was not terribly good in my opinion, but Microsoft having control over it can only be a good thing IMHO.
I think it provides a good integration. Some things might have been made better (like the unity project view. The constant reloading is also on of those things, but i think thats more of a VS issue then UnityVS).
My biggest issue with Visual Studio is it constantly asking me if I want to reload the project file. I know why it's happening (adding files, renaming files, changing build vars).. but the fact that it asks me 40+ times a day kills me.
[QUOTE=garry;45283381]My biggest issue with Visual Studio is it constantly asking me if I want to reload the project file. I know why it's happening (adding files, renaming files, changing build vars).. but the fact that it asks me 40+ times a day kills me.[/QUOTE]
Finally, somebody who shares my pain!
What's even worse is accidentally not saving something, switching back to VS and hitting "Reload" without thinking about it, and it completely blows away all of my code changes since the last save AND my undo history.
I'm pretty sure this supresses the reload message.
[IMG]http://bueno.alexgrist.com/i2B7H[/IMG]
It might suppress it, but it needs the reload. It just needs to auto-reload WITH a message stating that it did reload and if needed which ones weren't saved. Because the "Auto-load changes, if saved" is not very safe imo. Might cause confusion when suddenly your shit breaks because you used the old file or so witouth noticing.
Also, that message is not a dialog prompt, just a bubble that automatically disappears and is click trough and such.
[QUOTE=Alex_grist;45283398]I'm pretty sure this supresses the reload message.
[IMG]http://bueno.alexgrist.com/i2B7H[/IMG][/QUOTE]
Wouldn't that mean I have to manually reload every time I create a new file in Unity? That might be somewhat less than ideal...
BTW nice profile pic :)
Top Gear fan?
First option makes the dialog display and gives the option of reloading. The second option automatically reloads all saved files. So if a file is not saved, it will not be reloaded (which is kinda unsafe imo)
Should I bother with 2D lighting if I don't have pro?
Sorry, you need to Log In to post a reply to this thread.