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
0
Question by sam32x · Sep 05, 2011 at 03:14 AM · error

my script says OnCollisionEnter() error bce005 and it wont work

ok so im new to unity and im making an fps, this is the script i've made

 var health = 10;
 var something : GameObject;
 
 function Update ()
 {
 
 if (OnCollisionEnter(something)) {
 var health = -1;
  }
 }

i want to attach this to an enemy so when they collide with a bullet they will lose 1 health (i tried to put bullet instead of GameObject but it came up with an error)

when i try to build the game it says BCE0005: Unknown identifier: 'OnCollisionEnter' someone help plz

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
0

Answer by djmorrsee · Sep 05, 2011 at 03:23 AM

OnCollisionEnter doesnt work that way, its its own function. so instead of being within update, it would look something like this:

 function OnCollisionEnter (collision : Collision) {
 if(collision.gameObject == something){
 health -= 1;
 }
 }

Then obviously make sure 'something' and 'health' are defined correctly.

Note: Take syntax with a grain of salt, I don't normally code in java.

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 sam32x · Sep 05, 2011 at 03:29 AM 0
Share

now it says BCE0043: Unexpected token: collision.

avatar image djmorrsee · Sep 05, 2011 at 03:56 AM 0
Share

That's me not knowing java syntax. Itd be (collision : Collision) like unluckyBastard said. Not sure why the if isnt working, could you post your most up to date code?

avatar image vxssmatty · Sep 05, 2011 at 04:38 AM 0
Share

its not java, its javascript. And its not really javascript, its unityscript which is javascript-like syntax but using .net/mono environment.

avatar image
0

Answer by unluckyBastard · Sep 05, 2011 at 03:37 AM

 function OnCollisionEnter(c : Collision){
 //code here
 }
Comment
Add comment · Show 5 · 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 sam32x · Sep 05, 2011 at 03:52 AM 0
Share

thanks that fixed that bit but now it says unexpected token if -_-

avatar image sam32x · Sep 05, 2011 at 03:55 AM 0
Share

it looks like this now

 var health = 5;
 var something : GameObject;
 
 function OnCollisionEnter(c : Collision)
 
 if (collision.gameObject == something);
 {
 health : 1};
avatar image unluckyBastard · Sep 05, 2011 at 03:55 AM 0
Share

let me see your code

avatar image unluckyBastard · Sep 05, 2011 at 03:58 AM 0
Share

you have to take out the semicolon after the if statement if(collision.gameObject == something){ health -= 1; }

avatar image sam32x · Sep 05, 2011 at 04:13 AM 0
Share

well... the if error is till there and its telling me to put the semicolon back -.-

avatar image
0

Answer by vxssmatty · Sep 05, 2011 at 04:36 AM

var health = 5;

function OnCollisionEnter(collision : Collision) { if (collision.gameObject.name == "Bullet") //change Bullet to whatever you bullet is called, pay attention to caps. { health--; } }

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 sam32x · Sep 05, 2011 at 05:17 AM 0
Share

still have the error -_- i cant see why it doesnt just read it

avatar image vxssmatty · Sep 05, 2011 at 05:42 AM 0
Share

haha i know what was wrong... ok i've edited the post, try that... (EDIT: forgot a set of curly brackets)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Wierd error messages concerning audio play and pause? 1 Answer

Error CS1502 Help! 1 Answer

Script Error 4 Answers

Need Help | Door Opening Script Error 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