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 Woutervd · Apr 28, 2012 at 07:42 PM · javascriptcollisiontransform.positionrespawn

Script error: respawn upon collission

Hello!

I am trying to write a script where the player (in this case just a sphere) respawns (as in, goes back to it's original position) when it falls off-world. I wrote the following script:

 #pragma strict
 var position : Vector3;
 function OnCollisionEnter(collision:Collision) 
 { if( collision.gameObject.tag == "Finish" ); 
 {transform.position : Vector3(0, 0, 0)}; 
 }

When trying to execute it, I get the following error: Assets/Die.js(5,1): BCE0034: Expressions in statements must only be executed for their side-effects.

What is going wrong?

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

2 Replies

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

Answer by BiG · Apr 28, 2012 at 07:49 PM

Try with:

 #pragma strict
 var position : Vector3;
 function OnCollisionEnter(collision:Collision) 
 { 
    if( collision.gameObject.tag == "Finish" ) 
       transform.position = Vector3(0, 0, 0); 
 }

You have substituted an "=" with a ":", and this won't change the position. Also, you've ended the if statement with a ";". It should work now.

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
avatar image
0

Answer by Woutervd · Apr 30, 2012 at 07:16 PM

Thank you! I ended up using

 #pragma strict
 var position : Vector3;
 function OnCollisionEnter(collision:Collision) 
 { if( collision.gameObject.tag == "Finish" )
  {
  transform.position = Vector3(1,5,-2.8);
  rigidbody.velocity = Vector3(0,0,0);
  } 
 }

Which works great as a very basic respawn system. The biggest problem was indeed ending the if-statement with a semicolumn. This caused the script to not actually execute what was defined in the function.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How would I move an Object after collision? 1 Answer

Trouble with a respawn script 1 Answer

Adding sound javascript in unity2d 1 Answer

Object Collision PLEASE HELP!!! 1 Answer

How to add to a 3D object's length through code? 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