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 shane · Mar 12, 2010 at 11:03 PM · errorsyntax-errorbce0019

rigidbody' is not a member of 'UnityEngine.Object ?

I'm geting the error:

Assets/_Scripts/LookAtTarget.js(38,16): BCE0019: 'rigidbody' is not a member of 'UnityEngine.Object'. 

and here's the code and that line 38 is near the bottom:

var LookAtTarget:Transform; var damp = 6.0; var bullitPrefab:Transform; var savedTime=0;

function Update () { if(LookAtTarget) { var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);

     var seconds : int = Time.time;
     var oddeven = (seconds % 2);

     if(oddeven)
     {
         Shoot(seconds);
     }
 }

}

function Shoot(seconds) { if(seconds!=savedTime) { var bullit = Instantiate(bullitPrefab ,transform.Find("spawnPoint").transform.position , Quaternion.identity); bullit.rigidbody.AddForce(transform.forward * 1000); savedTime=seconds; }
}

I'm not sure what I've done wrong here, spent a few hours on this one...

Thank you.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Murcho · Mar 12, 2010 at 11:28 PM

Instantiate() returns type Object, not type GameObject as your code assumes, and as you are not using strong typing on your variable declaration of bullit, it is being created as an Object type.

I haven't coded in UnityScript for a while, so I can't quite remember the correct casting method, but I'm pretty sure this is right.

var bullit : GameObject = Instantiate(bullitprefab, transform.Find("spawnPoint").position, Quaternion.identity);

This code should cast the Object returned by Instantiate() to a GameObject, which will allow your follow code to work properly.

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 shane · Mar 13, 2010 at 02:27 PM 0
Share

Hey thanks a lot. I'm getting this now though:

Assets/_Scripts/LookAtTarget.js(36,47): UCE0001: ';' expected. Insert a semicolon at the end.

But there is a semicolon there...

Yes I'm obviously new to Unity coding hehe.

avatar image Eric5h5 · Mar 13, 2010 at 09:23 PM 0
Share

I edited the code so it should work now.

avatar image Murcho · Mar 14, 2010 at 12:00 AM 0
Share

Thanks Eric, I couldn't remember the correct casting for JS. Obviously JS sorts it out properly as long as you declare the variable type properly.

avatar image
3

Answer by Flimgoblin · Mar 13, 2010 at 07:56 PM

You need to either do:

var bullit:GameObject= Instantiate(...);

or

var bullit = Instantiate(...) as GameObject;

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 Lenn Dolling · Jul 24, 2011 at 02:50 AM 0
Share

was running into this issue when I was trying to Instantiate objects on the Android.. During PC runtime no errors would fireoff. Just added the casting and whoo hoo. All good!! 'xxxxxxxx' is not a member of 'UnityEngine.Object'. all fixed!!

avatar image
0

Answer by shane · Mar 13, 2010 at 08:36 PM

Ok.. haha where does that go in these two lines?:

        var bullit : GameObject = (GameObject)Instantiate(bullitprefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);

I tried using your two examples replacing var bullut : GameObject = but didn't know how to structure it properly and got more errors.

cheers.

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 Eric5h5 · Mar 13, 2010 at 09:26 PM 0
Share

You should be using comments rather than posting new answers. I edited $$anonymous$$urcho's answer so it should work.

avatar image
0

Answer by Min Won Ki · Apr 12, 2010 at 09:46 AM

You change source

var bullitPrefab:Transform;

var bullitPrefab:GameObject;

var bullit = Instantiate(bullitPrefab ,transform.Find("spawnPoint").transform.position , Quaternion.identity);

var bullit:GameObject = Instantiate(bullitPrefab ,transform.Find("spawnPoint").transform.position , Quaternion.identity) as GameObject;

and

re-seting bullitPrefab object in Main Camara

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 TroyTegeder · Dec 01, 2010 at 03:24 PM 0
Share

Thanks. This helped me out.

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

1 Person is following this question.

avatar image

Related Questions

'motorTorque' is not a member of 'System.Type'. 1 Answer

Accessing array in another script - Error message 2 Answers

I got a major question 1 Answer

Enabling / Disabling C# Scripts - Why am I getting the error "not a member of 'UnityEngine.Component'"? 1 Answer

Script Error (js) 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