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 Yoseki · Jun 20, 2014 at 11:02 AM · destroylevels

Unlockable Levels - Object Masking

Hello. This is my first post so plz excuse any mistakes. So, I have been trying to develop an Unlockable Level System. I've made lots of scripts but I can't seem to find out why it doesn't work. Here is what I have:

This loads the level at the level menu and then sets the room number for the try again feature.

Levelselecter.js

 public static var room: int = 1;
 var particle : GameObject;
 var rayCastHit : RaycastHit;
 var ray : Ray;
 
     function Update () {
         
             if(Input.GetMouseButtonDown(0))
             {
                 ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                 
                 if (Physics.Raycast (ray, rayCastHit))
                 {
                      if(rayCastHit.transform.name == "Cos1")
                     {
                     room =1;
                     Application.LoadLevel("Cosmos1");
                     
                     
                     }
                     
                     else if(rayCastHit.transform.name == "Cos2")
                     {
                     
                     room =2;
                     Application.LoadLevel("Cosmos2");
                     
                     
                     }
                     
                     else if(rayCastHit.transform.name == "Cos3")
                     {
                     Application.LoadLevel("Cosmos3");
                     room = 3;
                     
                     }
 //ETC to 20

Next, when the ball in the Level hits the portal to get to win the level it checks if the level the player was on was won for the first time (by making the UCosmos (Unlockedlevels variable) increased if the unlocked level is = to the room) and then sending the player back to the level menu to see the new unlocked level:

Ball.js

 var Crackle : GameObject;
 var Pong : AudioClip;
 public static var UCosmos: int = 1; //UCosmos is the variable that saves the number of Unlocked Levels in my pack Cosmos
 
 
 function Awake()
 {
 rigidbody.AddForce(0, -4, 0, ForceMode.Impulse);
 
 }
 
 function Update(){
 
 if(transform.position.y < -5){
 Application.LoadLevel("TryAgain");
 }}
 
 function OnCollisionEnter(theCollision : Collision){
 
 
 
 if(theCollision.gameObject.name == "Portal Cosmos"){
 rigidbody.velocity=Vector3.zero;
 rigidbody.angularVelocity=Vector3.zero;
 
 
 if(Levelselecter.room==1){
 if(UCosmos == 1){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==19){
 if(UCosmos == 19){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==18){
 if(UCosmos == 18){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==17){
 if(UCosmos == 17){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==16){
 if(UCosmos == 16){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==15){
 if(UCosmos == 15){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==14){
 if(UCosmos == 14){
 UCosmos += 1;
 }}
 
 
 else if(Levelselecter.room==13){
 if(UCosmos == 13){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==12){
 if(UCosmos == 12){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==11){
 if(UCosmos == 11){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==10){
 if(UCosmos == 10){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==9){
 if(UCosmos == 9){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==8){
 if(UCosmos == 8){
 UCosmos += 1;
 }}
 
 
 else if(Levelselecter.room==7){
 if(UCosmos == 7){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==6){
 if(UCosmos == 6){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==5){
 if(UCosmos == 5){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==4){
 if(UCosmos == 4){
 UCosmos += 1;
 }}
 
 else if(Levelselecter.room==3){
 if(UCosmos == 3){
 UCosmos += 1;
 }}
 
 
 else if(Levelselecter.room==2){
 if(UCosmos == 2){
 UCosmos += 1;
 }
 }
 else if(Levelselecter.room==20){
 if(UCosmos == 20){
 UCosmos += 1;
 }
 }
 Application.LoadLevel("Cosmos Levels");
 }
 audio.Play();
 Instantiate (Crackle, transform.position, transform.rotation);
 }`

 

So on the level selection page, there are all the level boxes. On everyone but lv 1, there is a black box called Cost.. (Cost2 goes on Cos2,etc). When the level was completed, I tries making it so that the UCosmos destroys the Cost blocks like so:

 var Cost20 : GameObject;
     var Cost19 : GameObject;
     var Cost18 : GameObject;
     var Cost17 : GameObject;
     var Cost16 : GameObject;
     var Cost15 : GameObject;
     var Cost14 : GameObject;
     var Cost13 : GameObject;
     var Cost12 : GameObject;
     var Cost11 : GameObject;
     var Cost10 : GameObject;
     var Cost9 : GameObject;
     var Cost8 : GameObject;
     var Cost7 : GameObject;
     var Cost6 : GameObject;
     var Cost5 : GameObject;
     var Cost4 : GameObject;
     var Cost3 : GameObject;
     var Cost2 : GameObject;
 
 
 function Update(){
 if(Ball.UCosmos == 2){
 Destroy(Cost2);
 }
 else if(Ball.UCosmos == 3){
 Destroy(Cost3);
 }
 else if(Ball.UCosmos == 4)
 {Destroy(Cost4);}
 else if(Ball.UCosmos >= 5)
 {Destroy(Cost5);}
 else if(Ball.UCosmos >= 6)
 {Destroy(Cost6);}
 else if(Ball.UCosmos >= 7)
 {Destroy(Cost7);}
 else if(Ball.UCosmos >= 8)
 {Destroy(Cost8);}
 else if(Ball.UCosmos >= 9)
 {Destroy(Cost9);}
 else if(Ball.UCosmos >= 10)
 {Destroy(Cost10);}
 else if(Ball.UCosmos >= 11)
 {Destroy(Cost11);}
 else if(Ball.UCosmos >= 12)
 {Destroy(Cost12);}
 else if(Ball.UCosmos >= 13)
 {Destroy(Cost13);}
 else if(Ball.UCosmos >= 14)
 {Destroy(Cost14);}
 else if(Ball.UCosmos >= 15)
 {Destroy(Cost15);}
 else if(Ball.UCosmos >= 16)
 {Destroy(Cost16);}
 else if(Ball.UCosmos >= 17)
 {Destroy(Cost17);}
 else if(Ball.UCosmos >= 18)
 {Destroy(Cost18);}
 else if(Ball.UCosmos >= 19)
 {Destroy(Cost19);}
 else if(Ball.UCosmos >= 20)
 {Destroy(Cost20);}
 }


The Problem is that it doesn't destroy the Cost blocks. Help?!?!??!?

Comment
Add comment · Show 3
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 Yoseki · Jun 20, 2014 at 10:54 AM 0
Share

BTW, there are no errors that it says in the system so thats why I don't know how to fix it.

avatar image HarshadK · Jun 20, 2014 at 11:25 AM 0
Share

That's pretty impressive for a 13 years old. :-) I didn't even had a computer back then when I was 13. :-(

Now to the actual problem.

you should get a reference to the Ball Script using (Considering both these scripts are on same game object):

 var ball : Ball = gameObject.getComponent("Ball") as Ball;

And change your every Ball.UCosmos to ball.UCosmos.

Also don't make your UCosmos variable in Ball.js static variable.

See if this solves your issue.

avatar image meat5000 ♦ · Jun 20, 2014 at 11:57 AM 0
Share

You create variables of type GameObject in your script but these do not link to any objects in the hierarchy. These internal objects will become destroyed just fine.

One way to solve this problem is to have the hierarchy GameObject destroy itself when the condition is met.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Random levels(scenes) without repeat them till last one is played 2 Answers

Can I export UDK levels to unity? 2 Answers

Locked levels 1 Answer

How to get Buildbox Set Up in Unity 2D 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