- Home /
frustrating building problem
i have made a script that is used to navigate levels, it works perfectly in unity, but when i build the project the script does not work! i can't seem to find the problem. could anybody tell me what is going on?
here is the code.
using UnityEngine;
using System.Collections;
public class Portal : MonoBehaviour {
public float number;
public bool hasEnoughChips;
public bool hasEnoughCodes;
public bool hasEnoughFloppys;
public bool Chip;
public bool Code;
public bool Flop;
public bool end;
public GameObject Player;
void Start () {
Player = GameObject.FindGameObjectWithTag ("pow");
}
void Update(){
float distance = Vector3.Distance(Player.transform.position, transform.position);
int cur_level = Application.loadedLevel;
if (Chip == true) {
if (Resources.control.Chip >= number) {
hasEnoughChips = true;
}
}
if (Code == true) {
if (Resources.control.Code >= number) {
hasEnoughCodes = true;
}
}
if (Flop == true) {
if (Resources.control.Flop >= number) {
hasEnoughFloppys = true;
}
}
if (distance<3){
if (Chip == true){
if(hasEnoughChips == true){
Application.LoadLevel(cur_level + 1);
}else{
Application.LoadLevel(0);
Resources.control.Save();
}
}
if (Code == true){
if(hasEnoughCodes == true){
Application.LoadLevel(cur_level + 1);
}else{
Application.LoadLevel(0);
Resources.control.Save();
}
}
if (Flop == true){
if(hasEnoughFloppys == true){
Application.LoadLevel(cur_level + 1);
}else{
Application.LoadLevel(0);
Resources.control.Save();
}
}
if (end == true){
Application.LoadLevel(0);
}
}
}
}
Did you add the Scenes to the Build in the Build Settings?
$$anonymous$$ay seem silly but you dont have the object its set on taged as editor only do you?
thaT is not it because it works perfectly fine with another script.
it is just too weird. i have re written the code multiple times and the same thing happens in the editor, but this script does not seem to work in the built project. i am very lost.
here is the latest version...
using UnityEngine; using System.Collections;
public class Portal : $$anonymous$$onoBehaviour { public float Amount; public float Chips; public float Codes; public float Flops; public bool needsChips; public bool needsCodes; public bool needsFlops; public int nextLevel; public GameObject Player; public float portalSize;
void Update(){
float distance = Vector3.Distance(Player.transform.position, transform.position);
Chips = Resources.control.Chip;
Codes = Resources.control.Code;
Flops = Resources.control.Flop;
if (needsChips == true) {
if (distance <= portalSize) {
if (Amount <= Chips) {
Application.LoadLevel (nextLevel);
} else {
Application.LoadLevel (0);
}
}
}
if (needsCodes == true) {
if (distance <= portalSize) {
if (Amount <= Codes) {
Application.LoadLevel (nextLevel);
} else {
Application.LoadLevel (0);
}
}
}
if (needsFlops == true) {
if (distance <= portalSize) {
if (Amount <= Flops) {
Application.LoadLevel (nextLevel);
} else {
Application.LoadLevel (0);
}
}
}
}
void OnDrawGizmosSelected() {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, portalSize);
}
}
Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.
Here at Unity Answers, Answer means Solution, not Response.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Unity not building used assets 1 Answer
Game shifts to lower right corner post build 0 Answers
Material/Shader issue 0 Answers
Can someone tell me what's the problem with my JDK? 1 Answer