I’m developing a 2D app on the iPhone and have some basic questions. I have the iPhone advanced version of Unity…
Where is the web page that lists the limitations of Unity iPhone vs. the regular version of Unity? I searched the site but couldn’t find it. For example, where are the specs on differences with transparency, textures, etc.? I’m not seeing some expected transparency effects.
My game is being developed for landscape mode (480 x 320). How do I tell Unity that my game should always be oriented with the iPhone horizontal? I built it in Unity with a 480 x 320 layout, but when it runs on the iPhone, it is displaying in vertical mode.
How do the Player settings affect the layout of my iPhone game? Shouldn’t I be setting Default Screen Width to 480 and Default Screen Height to 320 or vice versa? This didn’t seem to have an effect. In the tutorials, e.g. Match game, they are set to 1024 x 768.
I’m still a bit of a coding newbie but I always, in the first scene in my game, have an empty game object I rename to “GameController” and attach a GameController.js script to.
This game object gets to survive throughout the game (level loads etc) and the first bit of code (for the iPhone I’d put in) would be something like this.
// ----------- set up application variables ---------------
// set up default setting for iPhone
static var verticalOrientation;
static var screenCanDarken;
// set up global variable available throughout the game
static var instance : GameController; // identifies this script as a global item
// ----------- basic game functions ---------------
function Awake ()
{
// set screen orientation and sleep mode of device
iPhoneSettings.verticalOrientation = false;
iPhoneSettings.screenCanDarken = false;
}
function Start ()
{
// Make sure that the GameManager always survives level loads
instance = this;
DontDestroyOnLoad (this);
}
function Foo () ... etc etc etc
I am confused about something however. How do I access a function in the GameController from another script in another scene?
The Unity 1.1 racing tutorial states that a command such as this should work:
// Tell the game controller that the race is complete
var controller = FindObjectOfType(GameController);
if (controller)
// controller.SendMessage("CompletedRace");
However when I enter that in a script I receive the error:
‘SendMessage’ is not a member of ‘UnityEngine.Object’
I placed the DontDestroyOnLoad instruction in my GameController script, so I’m not sure why this script can’t find it?
function Start ()
{
// Make sure that the gamecontroller always survives level loads
DontDestroyOnLoad (this);
// Load the main menu
Application.LoadLevel ("MainMenu");
}
an object is no game object
you must cast the return to a game object first before you can use game object functionality.
The unityscript automagic does not exist on the iphone
Ok, but my GameController Script is in another scene. When I try to use GameObject.Find(Gamecontroller) I get the same error.
For the purposes of this example lets assume that my persistant GameObject is called ‘ControllerObject’ and my script is called ‘GameController’. This object resides in a scene called ‘GameStart’.
Now how would I access ‘GameController’ from a script called ‘RaceCar’ in a scene called ‘RaceScene’? I suppose I could create another GameObject in ‘RaceScene’ and attach the ‘GameController’ script to it, but then I would be creating multiple instances of it because it is never destroyed, right?
I finally settled on this:
var o_script : GameController;
o_script = GameObject.Find("ControllerObject").GetComponent(GameController);
o_script.SomeFunction();