Beginner questions

First of all, I have to say that I am rather impressed, from what I have seen in Unity. It seems to be something I have been trying to look for a while as a hobbyist programmer.

Secondly, I am sorry, that I am asking the questions in scripting section, even tho not all of them should be asked in here.

Like most other people, I was thinking of doing something like singleplayer JRPG as a starting project, which obviously isn’t really a good idea, but it’s more of experimenting with things.

  • The first thing that I came to notice when using Unity, is that it opens wrong version of Blender installation (using windows xp). Is there a way to tell Unity to launch Blender from specific location?

  • I like the C# as programming enviroment a lot more than js. so I was wondering, how crippled is the C# code in scripts? Like what version of .Net does Unity use for compiling? Ofcourse I can understand, that you cannot add winforms into project, but things like Ling, 4.0 dynamics, etc.

  • If I create in a script public variable, which is array of a class, that has more than 1 public varibale, how can I set these values through unity? For example I have Dialog.class, which has List. OneLiner.class on the otherhand has string text and GameObject speaker. So when I give the dialog-script to NPC, I can ensure that the interaction with that NPC creates a conversation, where more than 1 person can say things.

  • I was wondering about game states. I saw an example of someone doing game states with tons of switch-case thingies, but I kind of feel, that it just seems clumsy when the project keeps growing. So I was thinking of building a stack of states, which it pops out once it finishes that state. For example: { GameScene, Dialogs, CharacterMenu } or something like this, but in general they would be in a stack, where the last one in the stack is the one handling all logics related to it. Now the problem arises, where do I actually initialize all these Scenes? How can I make sure, that the scripts are loaded before pretty much anything is loaded? Would I actually need to create “initializeRunningScripts” -scene or is there some better place to set the scripts?

  • Is there a way to prohibit the Unity from calling update functions? For example lets say I press D to access menu of the game. I would then want the game to stop moving, in other words I wouldn’t call update for scenes objects, instead I would call update to menusGUI-item. Surely I could just stop calling updateAI and so on in the update function, but the problem is more about the fact, that the animation seems to be running, and calling pauseAnimation/resumeAnimation for all the items just doesn’t seem proper way to solve it.

  • Next thing, what I was pondering is about saving game. In my thoughts I was thinking something like general state of the game class. The class would consist something like Dictionary<string, value>, where string is anykind of variable, that needs to be saved, and value is the value of that. So what I was pondering is, that does the C# Unity uses work with class serialization?

  • Forgot one more thing to ask, is there keypressEvenet, where the keypress sends event only when the button is pressed/released? I could then implement velocity vector for moving objects around, instead of having to check keyboard state in every single update.

Ty in advance and sorry for newbie-like questions.

To pause animation and physics and such you can set time scale to 0. While it’s a bit of a hack it does the trick for most cases though you’ll need to code your menu to be time independent and not use things like delta time in your menus.

Check the documents for Input.GetButtonUp and Input.GetButtonDown events

In creation of a “person” in Unity. lets say a quest giver, you can create a class that handles communication. (Class being Monobehaviour or standard class) In that class you could easily put various text strings that handle dialog boxes. I would use a game controller to handle the actual dialog boxes though. This will allow you to keep track of who you are talking to, and what area that the communications are taking place.

You can handle this in many different ways. I think what you are talking about is a Modal menu which is not directly available through Unity. You can create the interface though using a GameController that handles the Modal interface. Look up windows in Unity. I think those would be a good starting ground for you.

For initializing all of these things, you would want to check the GUI section on the reference. to handle windows and such, you will want a GUI.Window.

The “scene” is not part of the GUI but is a camera. All GUI elements are loaded in on top of that. You can have multiple cameras and create multiple effects using the setup.

You would need to have a GameController that manages all of your GUI elements in a Modal environment. This would include pausing the game as well.

http://unity3d.com/support/documentation/ScriptReference/GUI.Window.html

Lastly, You can create a public class to handle all of this stuff if you need. So say you have a GameController object, and you made a public class called Game. You could put static properties and methods in that class and call them like so:

Game.AddWindow(myWindow);
Game.ShowGUI();

This is an example of what I am talking about, though I did not test it:

import System.Collections.Generic;

var game : Game;

function Start () {
	game = new Game();
}

class Window{
	var id : int;
	var title : String;
	var rect : Rect;
	var func : Object;
	
	function Window(inId : int, inTitle : String, inRect : Rect, inFunc : Object){
		id = inId;
		title = inTitle;
		rect = inRect;
		func = inFunc;
	}
	
	function ShowWindow(){
		rect = GUI.Window(id, rect, func, title);
	}
}

class Game{
	static var windows : List.<Window>;
	
	function Game(){
		windows = new List.<Window>();
	}
	
	static function AddWindow(id : int, title : String, rect : Rect, func : Object){
		windows.Add(new Window(id, title, rect, func));
	}
	
	static function ShowGUI(){
		for(var window : Window in windows){
			window.ShowWindow();
		}
	}
}