Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by JeppeNygaard · Dec 05, 2010 at 03:38 PM · iosbuildtestingrunbce0019

Build and run question, iOS, newbie question

I've made a little game - a very typical spaceship shooter (like space invaders - to try something completely new :))

Anyway - the game works just fine when I test it in unity and I get no compiling errors in the console, but when I chose to build and run to test the game on the iPhone i get these two messagea in the console:


Assests/flyBulletFly.js(10,32): BCE0019: 'rigidbody' is not a member of 'UnityEngine.Object".

Error building Player because scripts had compiler errors UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()


the script the message refers to looks like this:

var bulletSpeed : float; var prefabBullet : Transform;

function Update () {

if(Input.GetButtonUp("Jump")){

 var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
 instanceBullet.rigidbody.AddForce(transform.forward * bulletSpeed); 

}

}

Can someone help me please!

Thanks Jeppe (upcoming developer taking baby steps)

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

3 Replies

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

Answer by Eric5h5 · Dec 05, 2010 at 04:31 PM

Put "#pragma strict" at the top of all scripts when using JS with an iOS (or Android) target, and fix all resulting dynamic typing errors. For example, Instantiate returns Object, which is making instanceBullet be type Object, which works OK with dynamic typing (except slower), but won't work without dynamic typing. So you need to cast that to a GameObject in this case.

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 JeppeNygaard · Dec 11, 2010 at 08:52 PM 0
Share

I finally got my head around static and dynamic variables - thank you for pointing me in the right direction

avatar image
0

Answer by JeppeNygaard · Dec 05, 2010 at 05:40 PM

Put "#pragma strict" at the top of all scripts when using JS with an iOS (or Android) target

Thank you for this! ... when I add the "#pragma strict" the compiler will no longer accept my script, again referring to: 'rigidbody' is not a member of 'UnityEngine.Object".

What am I overlooking - rigidbody should indeed be part of the unityEngine?

the script looks like this:


var bulletSpeed : float; var prefabBullet : Transform;

function Update () {

if(Input.GetButtonUp("Jump")){

var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward * bulletSpeed); 

}

}


Can you help me?

Thanks Jeppe

Comment
Add comment · Show 2 · 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 Eric5h5 · Dec 05, 2010 at 06:11 PM 0
Share

As I said, you need to cast to a GameObject. rigidbody is not a member of UnityEngine.Object, just like the error says. It's a member of UnityEngine.GameObject. So declare instanceBullet to be a GameObject. In the future, comment on my answer or edit your question ins$$anonymous$$d, since this isn't an answer.

avatar image JeppeNygaard · Dec 06, 2010 at 04:33 PM 0
Share

Hi Eric,

Thank you so much for your answer. I've tried declaring instanceBullet as a GameObject ins$$anonymous$$d only to find even more errors. I know this may be way too much to ask but would you $$anonymous$$d giving me another hint? maybe even a concrete suggestion to how I could re-write my script? ... it would be a tremendous help!

avatar image
0

Answer by thung · Feb 18, 2011 at 05:36 PM

You have to type the Transform as a GameObject AND type the Instantiate function as a GameObject as well. I didnt need to add "#pragma strict" to make it work

var bullet:GameObject; var shootForce:float = 10;

function Update() {

if(Input.GetMouseButtonDown(0))
{
    var instanceBullet  = Instantiate(bullet,transform.position,Quaternion.identity) as GameObject;
    instanceBullet.rigidbody.AddForce(transform.forward *shootForce);
}   

}

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

How to build to IOS without a mac or hacks? 2 Answers

When I build and run my game my character and objects do not appear in the finished game 1 Answer

Build Game for Xbox 360 1 Answer

Distribute terrain in zones 3 Answers

iOS Build Error, runs normal in play mode 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