Hello, I hope i write to right section…
I try to create loop for activating special move once in awhile, when i wrote it and save, unity dont write any error but when i play it and loop turn on special move, game crash and not responding.
Here is script:
using UnityEngine;
using System.Collections;
public class PlayerControl: MonoBehaviour {
public float moveSpeed = 24;
public int hp = 5;
public bool timer = true;
public bool special = false;
int i = 0;
void Start () {
}
void Update () {
/* Here is problem!
if (timer == true) {
i++;
while (i > 100) {
special = true;
timer = false;
}
}
*/
if (Input.GetKey (KeyCode.W))
transform.Translate (Vector3.up * moveSpeed * Time.deltaTime, Space.World);
if (Input.GetKey (KeyCode.S))
transform.Translate (Vector3.down * moveSpeed * Time.deltaTime, Space.World);
if (Input.GetKey (KeyCode.A)) {
transform.Translate (Vector3.left * moveSpeed * Time.deltaTime, Space.World);
if (Input.GetKeyDown (KeyCode.LeftControl) & special == true) {
transform.position = new Vector3 (transform.position.x - 20, transform.position.y, transform.position.z);
timer = true;
special = false;
}
}
if (Input.GetKey (KeyCode.D)) {
transform.Translate (Vector3.right * moveSpeed * Time.deltaTime, Space.World);
if (Input.GetKeyDown (KeyCode.LeftControl) & special == true) {
transform.position = new Vector3 (transform.position.x + 20, transform.position.y, transform.position.z);
timer = true;
special = false;
}
}
GetComponent<PlayerGUI>().hpNum = hp;
}
void OnCollisionEnter2D(Collision2D collision){
if (collision.gameObject.tag == "EnemyBullet") {
hp -= 1;
if(hp == 0) Destroy(gameObject);
}
}
}
When i dont use commented code problem is solved… Do i anything bad? Or its problem in unity?