i have found a weird bug or im making a mistake somewhere. i’ll explain my problem here:
i made a bool in my public class for example"bool easy;“. then i wrote in void Start()“easy = false;”. i also did add in void update() print to control it"print(easy)”. i also have a NGUI button called EasyButton and it works so there is no problem with the button. here the code of the button:“public void EasyButton(){ easy = true; }” but when i run the game and check the print 20% says true and 80% says false. i really dont know why and how its possible that why i think it is a bug.
also sorry for my bad english.
an example of the code:
bool easy;
void Start(){
easy = false;
}
void Update(){
print(easy);
}
public void EasyButton(){
easy = true;
}
ill send down below the code in my script so maybe it is for you guys easier to find a solution:
using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class lvl7script : MonoBehaviour {
public bool Jump = false;
public bool Grounded = true;
public bool left;
public bool mid;
public bool right;
public bool pressed;
GameObject Panel;
public float speed;
bool easy;
bool normal;
bool hard;
// Use this for initialization
void Start () {
Time.timeScale = 0;
Panel = GameObject.Find("Panel");
easy = false;
normal = false;
hard = false;
}
// Update is called once per frame
void Update() {
if (Application.loadedLevel == 7)
{
if (Time.timeScale == 1)
{
print(easy);
print(normal);
print(hard);
if (easy)
{
speed = 0.3f;
Panel.GetComponent<Canvas>().enabled = false;
}
if (normal)
{
speed = 0.6f;
Panel.GetComponent<Canvas>().enabled = false;
}
if (hard)
{
speed = 0.9f;
Panel.GetComponent<Canvas>().enabled = false;
}
//controls
transform.Translate(0, 0, speed);
transform.Translate(0, Time.deltaTime, 0, Space.World);
//movement from 1 to other lane
if (mid == true && Input.GetKeyDown(KeyCode.LeftArrow) && !pressed)
{
transform.position = new Vector3(-5, (transform.position.y), (transform.position.z));
mid = false;
left = true;
right = false;
pressed = true;
}
if (mid == true && Input.GetKeyDown(KeyCode.RightArrow) && !pressed)
{
transform.position = new Vector3(5, (transform.position.y), (transform.position.z));
mid = false;
left = false;
right = true;
pressed = true;
}
if (left == true && Input.GetKeyDown(KeyCode.RightArrow) && !pressed)
{
transform.position = new Vector3(0, (transform.position.y), (transform.position.z));
mid = true;
left = false;
right = false;
pressed = true;
}
if (right == true && Input.GetKeyDown(KeyCode.LeftArrow) && !pressed)
{
transform.position = new Vector3(0, (transform.position.y), (transform.position.z));
mid = true;
left = false;
right = false;
pressed = true;
}
if ((Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow)) && pressed)
{
pressed = false;
}
//jump control
if (Jump == false && Input.GetKeyDown("up"))
{
Vector3 jump = new Vector3(0.0f, 400.0f, 0.0f);
GetComponent<Rigidbody>().AddForce(jump);
Jump = true;
Grounded = false;
}
//stay on 1 lane
if (mid == true && transform.position.x != 0)
{
transform.position = new Vector3(0, (transform.position.y), (transform.position.z));
}
if (left == true && transform.position.x != -5)
{
transform.position = new Vector3(-5, (transform.position.y), (transform.position.z));
}
if (right == true && transform.position.x != 5)
{
transform.position = new Vector3(5, (transform.position.y), (transform.position.z));
}
}
}
}
//collision for grounded
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Ground")
{
Grounded = true;
Jump = false;
}
}
public void EasyButton()
{
Time.timeScale = 1;
easy = true;
}
public void NormalButton()
{
Time.timeScale = 1;
normal = true;
}
public void HardButton()
{
Time.timeScale = 1;
hard = true;
}
}
here is a screenshot of the print result: Screenshot by Lightshot