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
2
Question by Daev · Mar 24, 2010 at 09:36 PM · iphonecomponentjavascript-specific

How to use GetComponent on Unity iPhone?

Hi, I'm working on the artificial intelligence of my game and looking for reference for iPhone/iTouch safe scripts.

When I try to use scripting from non-iphone source, I get an error for the command SimpleMove.

GetComponent (CharacterController).SimpleMove(direction);

It tells me SimpleMove is not a member of unityEngine.Component

Thanks

Daev

Comment
Add comment · Show 2
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 KvanteTore · Mar 24, 2010 at 09:54 PM 0
Share

retaged (chagned tag from ai to component) because the post is not directly AI related. Is this considered good practice? I just became a bit unsure. What do you guys think?

avatar image Eric5h5 · Mar 24, 2010 at 10:25 PM 0
Share

I changed the title, since this question has nothing to do with artificial intelligence.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Michael La Voie · Mar 24, 2010 at 09:42 PM

GetComponent returns a "Component", not the component type you request. You then have to cast that component as the type you want to access its specific functions and members.

Javascript:

var other : ScriptName = gameObject.GetComponent(ScriptName);

C#

ScriptName sn = gameObject.GetComponent<ScriptName>()

Your code looks like javascript so it should read:

var myController : CharacterController = GetComponent (CharacterController);
myController.SimpleMove(direction);
Comment
Add comment · Show 3 · 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 Daev · Mar 25, 2010 at 04:46 PM 0
Share

Yes this worked. Thank you.

avatar image Michael La Voie · Mar 25, 2010 at 05:50 PM 0
Share

Excellent. If it was helpful, please mark it as the accepted answer.

avatar image jesusluvsyooh · May 11, 2012 at 09:28 AM 0
Share

Yep this did the trick! Gotta modify it to fit your own variables and such but if you do that right it works 5/5

avatar image
1

Answer by Eric5h5 · Mar 24, 2010 at 10:21 PM

Using Javascript on the iPhone means all your scripts have an invisible "#pragma strict" attached to them, and have no ability to use dynamic typing.

(GetComponent(CharacterController) as CharacterController).SimpleMove(direction);
Comment
Add comment · 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

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

#ifdef UNITY_IPHONE equivalent for JavaScript 2 Answers

Get component in iPhone 1 Answer

Is using MonoDevelop worth it if you are writing in JavaScript and using Unity iPhone? 1 Answer

enabled is not a member of 'UnityEngine.Component 3 Answers

GetComponentsInChildren not working on iphone 1 Answer


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