- Home /
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613180210im_/https://answers.unity.com/themes/thub/images/avi.jpg)