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 Muth303 · Feb 13, 2014 at 05:25 AM ·

Help with OnTriggerEnter Issue

Hi im making a sidescroller game. When you fall off the level you die and it resets the level with this script here

 `#pragma strict
 var player : GameObject;
 
 function OnTriggerEnter(player : Collider){
     if(player.tag =="Player");
     Destroy(player.gameObject);
     Application.LoadLevel(Application.loadedLevel);
 }
     
 `

This is all fine and dandy. The issue is I have movable cubes you can push around. Now if you push one of those cubes off the edge instead of the PlayerRespawn collider ignoring it and only deleting objects with the tag "Player" it deletes the cube and reloads the level. If you guys can see any errors in my code can you please help? Or any advice with how to do this in a more efficient way would be much appreciated. If you have any questions about my code in helping you understand it please ask. Thanks a lot for all of your help, it's a strong programming community that makes games that much better.

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

1 Reply

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

Answer by whydoidoit · Feb 13, 2014 at 05:26 AM

I have a friend who once awoke from a nightmare shouting "Semi-colon" - you have the same problem :)

Your if statement does nothing (because of the semi-colon) what you want is this:

 function OnTriggerEnter(player : Collider){
     if(player.tag =="Player") {
         Destroy(player.gameObject);
         Application.LoadLevel(Application.loadedLevel);
     }
 }
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 Muth303 · Feb 13, 2014 at 06:22 AM 0
Share

I've been program$$anonymous$$g for eight years. I am so mad, happy, depressed, and feel like a baby penguin when their mother has been eaten by a seal. I hate my self. Thank you. I shouldn't make such a stupid mistake. I am so so so just so I cant even explain it. Its just Idk. I am broken just like my game used to be.

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

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

Related Questions

few questions about unity3d from a total newbie - long post >.> 0 Answers

How can i create anouther jump script? 0 Answers

I need help... 3 Answers

How to keep players from falling off the map 4 Answers

OnTriggerStay2D not returning false when outside trigger 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