Bool paused in collision
Good day.
I making the movement script with bool paused. (if(col.gameObject.tag == "Bullet(Clone)") paused true... but it doesn't work.
Here is the code:
public class Tank2 : MonoBehaviour {
public GameObject Bullet;
public float moveSpeed = 10f;
public float turnSpeed = 120f;
public Text Vyhra;
public GameObject protivnik;
public GameObject teleport;
public Text ScoreA;
public int TankA;
public bool paused;
void Start () {
gameObject.GetComponent<Renderer>().material.color = Color.green;
TankA = 0;
SetTextA ();
}
void OnPausedGame (){
paused = true;
}
void OnExitGame (){
paused = false;
}
// Update is called once per frame
void Update () {
if (!paused) {
if (Input.GetKey (KeyCode.W)) {
transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.S)) {
transform.Translate (-Vector3.forward * moveSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.A)) {
transform.Rotate (-Vector3.up * turnSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.D)) {
transform.Rotate (Vector3.up * turnSpeed * Time.deltaTime);
}
}
}
void OnCollisionStay(Collision col) {
if(col.gameObject.name == "Kulka(Clone)") {
Destroy (col.gameObject);
TankA = TankA + 1;
SetTextA();
StartCoroutine (dcoLoadLevel ("tanky", 5.0f));
}
}
IEnumerator dcoLoadLevel(string tanky, float delay) {
yield return new WaitForSeconds (delay);
teleport.transform.position = new Vector3(13, 8f, 21);
this.transform.position = new Vector3(18, 8f, 21);
}
void SetTextA(){
ScoreA.text = "Score: " + TankA.ToString ();
if (TankA >= 10) {
Vyhra.text = "Vyhral cerveny hrac!";
StartCoroutine (coLoadLevel ("menu", 5.0f));
}
}
IEnumerator coLoadLevel(string Menu, float delay) {
yield return new WaitForSeconds (delay);
Application.LoadLevel (Menu);
}
}
Thank you for help
I don't see the paused bool being set to true anywhere. You might want to set it to false in Start() too. I'm assu$$anonymous$$g when you set the boolean to true, you have coded else where something along the lines of,
Time.timeScale = 0f;
I think this will only work if you're working with Time.deltaTime;
Hope that helps, if not will need more detail.
I paste paused = true on start() but its still doesn't work.
Time.timeScale = 0f; Can't work here, because i have IE numerator and i think that will not countdown.
Answer by JunekCZ · Apr 20, 2016 at 02:19 PM
Okey i solve that!
I dont know that i must make that rigidbody.
But thank you for comment ;).
Your answer
Follow this Question
Related Questions
Limit of a move for position 1 Answer
hi guys am having a problem with my player 0 Answers
Shopping Cart Movement 0 Answers
How to check if an object has collided from another script? 1 Answer