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 guitargodd97 · Jul 02, 2012 at 10:55 PM · endgamenext level

Level Compete Spot

Okay, I am currently using these two scripts to tell my game when to end the level. What do I do to make it so that the script comes into play when the character touches a certain area?

var message: Texture2D; //you put text in here, that you made in photoshop, the "you win!" type deal var button: Texture2D; //this would be text, that you made in photoshop, that says next level var nCrystals = 0; //starting number of crystals var neededCrystals = 10; //number needed. Just change this in the editor var nextLevel = 0; //this would be the # of the next level, if you use it

function OnTriggerEnter( hit : Collider ) {

if (nCrystals >= neededCrystals) {

 GUI.DrawTexture(Rect((Screen.width-message.width)/2, 200, message.width, message.height), message);
   
  if (GUI.Button(Rect((Screen.width-button.width)/2, 400, button.width, button.height), button))
  
 {      

 Application.LoadLevel(nextLevel);  
    

} } }

And this one

var explosion : Transform; //this will be the particle, i.e. fireworks var controlScript : LevelCompleted; // drag here the object that has the LevelCompleted script static var crystal = 0; //this isn't used anymore in this script static var point = 0; //how many points you receive var playFireworks = false; // this isn't really nescessary

function OnTriggerEnter(other: Collider) { if (other.tag == "wormy") //This is what your character is tagged as. You have to create a tag and tag it as this //or create your own tag and change it in this script { controlScript.nCrystals++; //This is the level complete script Destroy(gameObject); //this causes the crystals to self destruct playFireworks = true; //states that fireworks will come out of the crystal when it's collected

   if (playFireworks == true)
   {
   var explosion = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
   crystal += 1;
   point += 5000;
   playFireworks = false;
   }
   
   if (playFireworks == false)
   {
   Destroy(gameObject);
   }
   }

}

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 torrente · Jul 03, 2012 at 01:38 AM 0
Share

Hey Hunter, are you asking how to implement these in your game or are these scripts giving you an error or perhaps not throwing a collision?

avatar image guitargodd97 · Jul 03, 2012 at 01:59 AM 0
Share

The top script was working fine when it was function OnGUI() but then when I changed it to function OnTriggerEnter it hasn't been working. I thought changing it would make it so that when I attached it to a cube it would do the same thing when the character collided with it but it doesn't.

1 Reply

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

Answer by torrente · Jul 03, 2012 at 03:01 AM

I see. Yes, the Gui needs to be put back in to function OnGUI(), so put your two GUI items back there. Then, add in a boolean that is set to true when the collision is fired, something like this:

var message: Texture2D; //you put text in here, that you made in photoshop, the "you win!" type deal var button: Texture2D; //this would be text, that you made in photoshop, that says next level var nCrystals = 0; //starting number of crystals var neededCrystals = 10; //number needed. Just change this in the editor var nextLevel = 0; //this would be the # of the next level, if you use it //ADD THE NEXT LINE /////////////////////////// var levelComplete = false;

//CHANGE THIS TO SOMETHING LIKE THIS ///////////////////////// function OnTriggerEnter( hit : Collider ) {

if (nCrystals >= neededCrystals) {
levelComplete = true; } }

// ADD THE FOLLOWING ////////////////////////////////////// function OnGUI() {

if(levelComplete) { //PUT YOUR LEVEL COMPLETE GUI HERE /////////////////////// } }

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycast/Collider End Level 1 Answer

How can I delay Application.Loadlevel for a few seconds? 2 Answers

Beginner - End game by touching certain object 1 Answer

i want the player to match 5 items correctly before next scene appears. 1 Answer

End Game When Time Is Up 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