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 baukjespirit · Jan 12, 2015 at 11:27 AM · androidoncollisionenterloadlevelsetactive

Next level loads in Unity, but doesn't on Android

We're making a simple maze game for Android with the Durovis Dive, but there's this weird problem that doesn't make sense.

In the maze you have to look for keys and then find the exit to escape the maze. But when you're on collision with the exit and you have the key, it doesn't set the next level active. I used to use 'Application.LoadLevel("level2")', but that didn't work so I tried this cheap solution with the 'SetActive'.

When testing in Unity itself everything works perfectly (both the Application.LoadLevel and the cheap Setactive solution), but when i try it on android, it doesn't work.

Example:

 void OnCollisionEnter(Collision s)
     {
         if ((s.gameObject == exit.gameObject) && (keyPickUp))
         {   
             level1.gameObject.SetActive(false);
             level2.gameObject.SetActive(true);  
         }
 }

Here's the whole script:

 using UnityEngine;
 using System.Collections;
 
 public class Movement : MonoBehaviour 
 {
     public bool move = false;
     public bool pressedButton = false;
 
     // BUTTONS
     public GameObject buttons;
     public float buttonsRot;
     public GameObject startButton;
     public GameObject stopButton;
     public GameObject startButtonP;
     public GameObject stopButtonP;
 
     // KEYS
     public GameObject key1;
     public GameObject key2;
 
     // EXITS
     public GameObject exit;
     public GameObject exit2;
 
     // LEVELS
     public GameObject level1;
     public GameObject level2;
 
     // TIPS
     public GameObject tip1;
     public GameObject tip2;
 
     public bool keyPickUp = false;
     public bool key1Destroy = false;
     public bool key2Destroy = false;
     public bool key3Destroy = false;
     public bool key4Destroy = false;
     public bool key5Destroy = false;
     public float characterRotation;
     public float lookDownTime = 0.0f;
 
     // MISC
     public GameObject paintBrush;
     public GameObject sword;
     public GameObject swordInScene;
     public GameObject bush;
 
     // Use this for initialization
     void Start () 
     {
         key1Destroy = false;
         key2Destroy = false;
         key3Destroy = false;
         key4Destroy = false;
         key5Destroy = false;
     }
     
     // Update is called once per frame
     void Update () 
     {
         characterRotation = this.transform.rotation.x;
         Debug.Log(keyPickUp);
         //Debug.Log(this.transform.rotation.x);
 
         // BUTTON POSITION
         buttons.transform.eulerAngles = new Vector3(buttons.transform.eulerAngles.x, this.transform.eulerAngles.y, buttons.transform.eulerAngles.z);
         startButton.transform.position = new Vector3(this.transform.position.x, startButton.transform.position.y, this.transform.position.z);
         stopButton.transform.position = new Vector3(this.transform.position.x, stopButton.transform.position.y, this.transform.position.z);
         startButtonP.transform.position = new Vector3(this.transform.position.x, startButtonP.transform.position.y, this.transform.position.z);
         stopButtonP.transform.position = new Vector3(this.transform.position.x, stopButtonP.transform.position.y, this.transform.position.z);
         
         // IF MOVE IS TRUE, SWITCH BUTTONS AND MOVE
         if (move)
         {
             this.transform.Translate(Vector3.forward * 0.03f);
             startButton.SetActive(false);
             stopButton.SetActive(true);
             startButtonP.SetActive(true);
             stopButtonP.SetActive(false);
             Destroy(tip1);
         }
         if (!move)
         {
             startButton.SetActive(true);
             stopButton.SetActive(false);
             startButtonP.SetActive(false);
             stopButtonP.SetActive(true);
         }
 
         if (this.transform.position.y != 1.0f)
         {
             this.transform.position = new Vector3(this.transform.position.x, 1.0f, this.transform.position.z);
         }
 
         if (this.transform.eulerAngles.x > 65.0f && this.transform.eulerAngles.x < 91.0f)
         {
             lookDownTime++;
             if (lookDownTime >= 100.0f)
             {
                 paintBrush.animation.Play("verf");
                 Destroy(tip2);
             }
 
             if (!pressedButton)
             {
                 move = !move;
             }
             pressedButton = true;
         }
         else
         {
             if (lookDownTime >= 100.0f)
             {
                 lookDownTime = 0.0f;
                 paintBrush.animation.Play("idle");
                 //paintBrush.transform.eulerAngles = new Vector3(-47.68536f, 27.88486f, -38.18671f);
                 //paintBrush.transform.position = new Vector3(-0.282f, -0.09f, 0.68f);
             }
             pressedButton = false;
         }
         /*if (!animation["swordHit"].enabled)
         {
             animation.Play("swordIdle");
         }*/
         
 
     }
 
 
     void OnCollisionEnter(Collision s)
     {
         if (s.gameObject == key1.gameObject)
         {
             keyPickUp = true;
             key1Destroy = true;
             //sleutel.renderer.enabled = false;
             Destroy(key1);
         }
         if (s.gameObject == key2.gameObject)
         {
             keyPickUp = true;
             key2Destroy = true;
             //sleutel.renderer.enabled = false;
             Destroy(key2);
         }
         if ((s.gameObject == exit.gameObject) && (keyPickUp))
         {   
             Debug.Log("IT WURKETTTT!");
             level1.gameObject.SetActive(false);
             level2.gameObject.SetActive(true);  
         }
         if (s.gameObject == exit2.gameObject)
         {
             if (keyPickUp)
             {
                 Application.LoadLevel("Level3");
             }
         }
         if (s.gameObject == swordInScene.gameObject)
         {
             Destroy(swordInScene);
             sword.gameObject.SetActive(true);
         }
         /*if (s.gameObject == bush.gameObject)
         {
             sword.animation.Play("swordHit");
             if (animation["swordHit"].enabled)
             {
                 Destroy(bush);
             }
         }*/
     }
 }
 

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

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

2 People are following this question.

avatar image avatar image

Related Questions

How to load a level after 30 seconds? 3 Answers

OpenIAB - billing plugin. It works only once! need HELP! 1 Answer

Android: lost textures with Home button/background? 1 Answer

Load Scene. Efficiency question 3 Answers

Android: Reloading scene causes graphics bug 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