x


Javascript in Unity, Including iPhone API's (Objective C?)

Hi guys,

I'm just getting started in unity, have been experimenting/following tutorials etc, and was just wondering something.

I'd like to get started in making iPhone games using Unity, but I have been learning to script in JavaScript. Apparently iPhone uses Objective C for its API's..?

I was wondering how it would work if I want to access iPhone specific features such as the new Gaming Network through unity script. Can these functions still be called?

Also, I've only got Unity Basic, and was intending on starting development on a game using it, and then purchase the Unity iPhone licence and port it to iPhone. Is there anything I should not include in my scripting or in the game in general, to make porting later easier?

Sorry if these seem like dumb/n00b questions! I'm learning all I can through searching out on my own, but some things like these I'm still unclear on since I can't test out myself at this point.

Thanks in advance! This community is fantastic. Been such a big help to me so far.

more ▼

asked Apr 10 '10 at 11:59 AM

MooseTrap gravatar image

MooseTrap
89 6 7 16

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The classes for some iPhone APIs (touch/accelerometer/keyboard/etc.) are included in both Unity iPhone Basic and Advanced. Also you can use any iPhone API, not just those that Unity supports. But for those you have to program in XCode, and make some kind of bridge to get the results to the Unity side. In this case it's fastest and most convenient to use plugins with iPhone Advanced, but there are other ways (typically passing data using PlayerPrefs).

As far as Javascript programming goes, Unity iPhone doesn't allow dynamic typing. If you put "#pragma strict" at the top of your scripts in regular Unity, you get the same effect, so it's a good idea to always include this if you intend to use Unity iPhone. 99% of your code won't change, but there are a few areas where you have to explicitly type things, where normally you're probably using dynamic typing (usually with GetComponent).

more ▼

answered Apr 10 '10 at 01:32 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

Oh, I see. I'll read up on PlayerPrefs. Is there anything else I should check out before diving into iPhone?

Thanks!

Apr 10 '10 at 01:49 PM MooseTrap

@MooseTrap: Make sure you read the iPhone-specific parts of the Unity iPhone docs. They aren't available on-line, so you have to read them locally...they come with Unity iPhone and initially look the same as the standard Unity docs, but there's some important stuff in them. Also I edited my answer to include some info about Javascript.

Apr 10 '10 at 01:58 PM Eric5h5

@Eric5h5 Thanks Eric! Just a question about Typing. I'm learning these programming concepts as I go, have I got this correct?

Static Typing: Declare variables and their type at the start of the script Dynamic Typing: Declare the variables and their type as they are needed

Is this correct, or have I got it all wrong? I just did some reading and that's what I got from it... Have I misunderstood?

Thank you for your help.

Apr 10 '10 at 02:25 PM MooseTrap

@MooseTrap: Actually no, dynamic typing means that the type is figured out at runtime. For example, var myMesh = GetComponent(MeshFilter).mesh; will work with regular Unity because it figures the type for you at runtime, but it won't work with #pragma strict or Unity iPhone, because "mesh" isn't a member of Component (which is what GetComponent returns). Instead you have to do var mesh = (GetComponent(MeshFilter) as MeshFilter).mesh; in order to cast the GetComponent call to the correct type. Or two lines: var mf : MeshFilter = GetComponent(MeshFilter); var myMesh = mf.mesh;

Apr 10 '10 at 04:29 PM Eric5h5

actually this does not seem to work anymore. nowadays you have to use GetComponent.<MeshFilter>().mesh

May 07 '11 at 06:01 AM ina
(comments are locked)
10|3000 characters needed characters left

you can only use iphone apis that unity supports. unity has some classes for iphone apis in it's iphone version but they are not available in the license that you currently have. try to write fast code and read th iphone tutorial in this page also take a look at this page. at the end unity gets your project and compiles it into ARM assembly code with Xcode. if you have a mac computer just download the 30 day trial of unity iphone and see how things work. reading the tutorial can help even if you don't have access to a mac computer. the most important things that you should think about them are your assets. they should be low resolution/polygon. don't use too many rigidbodies or too many particles.

more ▼

answered Apr 10 '10 at 01:02 PM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

Awesome, cheers Ashkan! I'll check out those links and trial of Unity iPhone.

Apr 10 '10 at 01:12 PM MooseTrap
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5086
x3460
x2000
x85
x22

asked: Apr 10 '10 at 11:59 AM

Seen: 3245 times

Last Updated: Apr 10 '10 at 11:59 AM