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
1
Question by BlackWingsCorp · Dec 27, 2012 at 10:17 PM · bce0044uce0001bce0043compilers

scripting colliders errors

hey guys newbie dev. here, I was testing a script that plays a sound when the player character collides with the door: function Start () { private var doorIsOpen : boolean = false; private var doorTimer : float = 0.0; private var currentDoor : GameObject; var doorOpenTime : float = 3.0; var doorOpenSound : AudioClip; var doorShutSound : AudioClip; } function Update () {

} function OnControllerColliderHit(hit : ControllerColliderHit){ if(hit.gameObject.tag == "playerDoor" && doorIsOpen == false){ function OnControllerColliderHit(hit: ControllerColliderHit){ if(hit.gameObject.tag == "playerDoor" && doorIsOpen == false){ OpenDoor(hit.gameObject); } } } } function OpenDoor(door : GameObject){ doorIsOpen = true; door.audio.PlayOneShot(doorOpenSound); }

And here's what console displays: PlayerCollisions.js(17,10):BCE0044: expecting (, found 'OnControllerCollideHit'. PlayerCollisions.js(17,34):BCE0043: Unexpected token: hit PlayerCollisions.js(17,61): UCE0001: ';' expected insert a semicolon at the end. PlayerCollisions.js(18,1): BCE0043: Unexpected token: if PlayerCollisions.js(18,62): UCE0001: ';' expected insert a semicolon at the end. PlayerCollisions.js((19,25): BCE0044: expecting : found ';'

Thank you in advance guys.

Comment
Add comment · Show 4
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 MattG · Dec 27, 2012 at 11:47 PM 1
Share

White space will help people read that.

avatar image clunk47 · Dec 28, 2012 at 03:00 AM 2
Share

Please edit your code and format it using the "10101001" Button.

avatar image BlackWingsCorp · Dec 28, 2012 at 05:24 AM -1
Share

sorry about that the internet freezed while I was writing it so I had to copy/paste the question didn't notice it became like this so here: $$anonymous$$y script:

function Start () {

private var doorIsOpen : boolean = false;

private var doorTimer : float = 0.0;

private var currentDoor : GameObject;

var doorOpenTime : float = 3.0;

var doorOpenSound : AudioClip;

var doorShutSound : AudioClip;

}

function Update () {

}

function OnControllerColliderHit(hit : ControllerColliderHit){

if(hit.gameObject.tag == "playerDoor" && doorIsOpen == false){

function OnControllerColliderHit(hit: ControllerColliderHit){

if(hit.gameObject.tag == "playerDoor" && doorIsOpen == false){

OpenDoor(hit.gameObject);

}

}

}

}

function OpenDoor(door : GameObject){

doorIsOpen = true;

door.audio.PlayOneShot(doorOpenSound);

}

Consoles errors display:

PlayerCollisions.js(17,10):BCE0044: expecting (, found 'OnControllerCollideHit'.

PlayerCollisions.js(17,34):BCE0043: Unexpected token: hit.

PlayerCollisions.js(17,61): UCE0001: ';' expected insert a semicolon at the end.

PlayerCollisions.js(18,1): BCE0043: Unexpected token: if

PlayerCollisions.js(18,62): UCE0001: ';' expected insert a semicolon at the end.

PlayerCollisions.js((19,25): BCE0044: expecting : found ';'

avatar image clunk47 BlackWingsCorp · Dec 28, 2012 at 05:28 AM 1
Share

No problem, I've actually already fixed the code and posted my answer below.. See if that works for you.

1 Reply

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

Answer by clunk47 · Dec 28, 2012 at 03:10 AM

You need to define your variables OUTSIDE of your functions, and you don't want to use a function twice. You had your OnControllerColliderHit function defined twice. There were a ton of brackets in the wrong place, a condition OUTSIDE of your IF statement... Then you had a function inside of another function. Try this, I hope this is what you were going for.

 private var doorIsOpen : boolean = false; 
 private var doorTimer : float = 0.0; 
 private var currentDoor : GameObject; 
 var doorOpenTime : float = 3.0; 
 var doorOpenSound : AudioClip; 
 var doorShutSound : AudioClip;
 
 function Start () 
 { 
 
 } 
 
 function Update () 
 {
 
 } 
 
 function OnControllerColliderHit(hit : ControllerColliderHit)
 { 
     if(hit.gameObject.tag == "playerDoor" && doorIsOpen == false)
     {
         OpenDoor(hit.gameObject);
     }
 }
 
 function OpenDoor(door : GameObject)
 { 
     doorIsOpen = true; 
     door.audio.PlayOneShot(doorOpenSound); 
 }
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 BlackWingsCorp · Dec 28, 2012 at 10:20 AM 1
Share

Thank a billion times bro, you're a life saver

avatar image clunk47 · Dec 28, 2012 at 05:26 PM 1
Share

Not a problem at all man :)

If this resolves your issue, if you don't $$anonymous$$d accepting / voting up my answer, I would be greatly appreciative. I've voted up your question so now you have the ability to vote up if you wish :)

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can solve these errors in my java script 1 Answer

3 java errors on a basic shooting script? 2 Answers

Unity to Iphone Unity iPhoneTouchPhase.Ended problems 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Javascript Expecting Errors ';' & '=' 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