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 Fifra · Jan 07, 2013 at 11:40 AM · collisiontreeexit

Exit on Collision

HI guys, I'm very new to unity and the only programming language i know is Java. I have an assignment to make a small interactive game using any program I want and so i chose unity. Now i am making an FirstPerson game similar to slenderman (but instead of finding 8 pages i have to find 1 fire). Graphichs and movements are working correctly, now all i need is an exit and to make the play not pass in trees. and you help me please. Thank you :)

PS: Explain in detail please as I have scouted the forums for answers and still have not managed to do this. Thx again

 #pragma strict
 
 function Start () {
 
 }
 
 function OnCollisionEnter (Hit: Collision){
 
 if(Hit.gameObject.tag == "FirstPersonControl"){
     
 
      print("Worked");
      Application.Quit();  
    
   }
   }
 
 function Update () {
 
 }

The main problem i have is what is the coding for when my Player collides with fire to trigger the end of game.

Comment
Add comment · Show 2
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 $$anonymous$$ · Jan 07, 2013 at 02:14 PM 0
Share

As I pointed out earlier, tags are strings, so unless FirstPersonControl is a string variable holding the actual tag you want to use, use "FirstPersonControl" like this. Also, you want to put this script on the fire object, because the player can't collide with itself. Also, you need to use #pragma strict, and not pragma strict. Then if you put this script on your fire object, it should work.

avatar image $$anonymous$$ · Jan 07, 2013 at 02:19 PM 0
Share

Note: JavaScript's name doesn't mean that JavaScript has anything to do with Java. If you use Java and worked with statically typed code, you should find C# more familiar than JavaScript.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Piflik · Jan 07, 2013 at 11:49 AM

For the trees you need a collider component. Depending in how you created the trees in the first place, the probably best solution would be to add Capsule Colliders to each tree prefab.

It is not clear to me, what you mean with exit...do you want to quit the game (Application.Quit()) or load a new/the same level (Application.LoadLevel()) or do something completely different?

PS: If you want detailed answers, you need to post detailed questions.

Comment
Add comment · Show 4 · 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 $$anonymous$$ · Jan 07, 2013 at 12:00 PM 0
Share

According to the **docs**, trees can only have Capsule Collider. So you attach a capsule collider to your model in the scene view, scale it to your tree as you see fit, and save that out to a prefab. Then feed that prefab to the Terrain tool's tree generator, like the page in the link shows.

avatar image Piflik · Jan 07, 2013 at 12:39 PM 0
Share

If he has his own tree, he can use whatever collider he wants. I'd still recommend a caspule, since that gives him the most desired result from a gameplay perspective.

avatar image Fifra · Jan 07, 2013 at 01:09 PM 0
Share

the tree is part of the trerrain. how do i add a capsule collider? And i have creat tree colliders checked

avatar image Piflik · Jan 07, 2013 at 01:55 PM 0
Share

I only tried it once to help a friend, and only used the standard tree that comes with the terrain assets, but there I just selected the prefab in the prohect folder and added a capsule collider. I placed an instance of that prefab in the scene (a real gameobject, not as part of the terrain) to position the collider correctly an then applied the changes to the prefab. After that all trees on the terrain also had colliders.

avatar image
0

Answer by Fifra · Jan 07, 2013 at 01:09 PM

And yes i want the game to quit i have tried the code application.quit() but its not working, i did a print working before it during testing and that is not working as well. the code i'm trying is:

pragma strict

function Start () {

}

function OnCollisionEnter (Hit: Collision){

if(Hit.gameObject.tag == FirstPersonControl){

  print("Worked");
  Application.Quit();  
   

} }

function Update () {

}

and i have attached it to the cylinder of the first person controller

Comment
Add comment · Show 7 · 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 $$anonymous$$ · Jan 07, 2013 at 01:20 PM 0
Share

Application.Quit() works, except when running in the editor or in a web player. Build your game and test it as a standalone.

avatar image Fifra · Jan 07, 2013 at 01:30 PM 0
Share

can't build as OnCollisionEnter is giving me errors: Script error: OnCollisionEnter

avatar image $$anonymous$$ · Jan 07, 2013 at 01:36 PM 0
Share

Ah, I see.. tags are strings, that's why you have compile error. Use (Hit.gameObject.tag == "FirstPersonControl") ins$$anonymous$$d. Also keep in $$anonymous$$d that tags are not object names. By the way, why are you attaching this script to the first person controller?

avatar image Fifra · Jan 07, 2013 at 01:44 PM 0
Share

The error has now changed to: The referenced script on the Behavior is missing!

where sould i attach it if not the person? with the obejct?

avatar image Fifra · Jan 07, 2013 at 01:47 PM 0
Share

and the old one is showing again: Script error: OnCollisionEnter This message parameter has to be of type: Collision The message will be ignored.

Show more comments

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

9 People are following this question.

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

Related Questions

Tree Colliders are not Triggers 1 Answer

Tree collision 1 Answer

OnTriggerExit won't detect player? 1 Answer

Tree collision 1 Answer

My trees have their collider misplaced 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