Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by MooseTrap · Apr 10, 2010 at 11:59 AM · javascriptiphoneapiporting

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Eric5h5 · Apr 10, 2010 at 01:32 PM

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).

Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MooseTrap · Apr 10, 2010 at 01:49 PM 0
Share

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

Thanks!

avatar image Eric5h5 · Apr 10, 2010 at 01:58 PM 0
Share

@$$anonymous$$ooseTrap: $$anonymous$$ake 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.

avatar image MooseTrap · Apr 10, 2010 at 02:25 PM 0
Share

@Eric5h5 Thanks Eric! Just a question about Typing. I'm learning these program$$anonymous$$g 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.

avatar image Eric5h5 · Apr 10, 2010 at 04:29 PM 1
Share

@$$anonymous$$ooseTrap: Actually no, dynamic typing means that the type is figured out at runtime. For example, var my$$anonymous$$esh = GetComponent($$anonymous$$eshFilter).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). Ins$$anonymous$$d you have to do var mesh = (GetComponent($$anonymous$$eshFilter) as $$anonymous$$eshFilter).mesh; in order to cast the GetComponent call to the correct type. Or two lines: var mf : $$anonymous$$eshFilter = GetComponent($$anonymous$$eshFilter); var my$$anonymous$$esh = mf.mesh;

avatar image ina · May 07, 2011 at 06:01 AM 0
Share

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

Show more comments
avatar image
0
Best Answer

Answer by Ashkan_gc · Apr 10, 2010 at 01:02 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MooseTrap · Apr 10, 2010 at 01:12 PM 0
Share

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

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Unity iPhone and Unity Desktop Scripting Differences 2 Answers

TPS Camera with Joystick (Android) 0 Answers

Flipping textures 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges