Hello, I’m attempting to code a wall that disappears once the count reaches a certain number. The problems I’m having are that I’m not sure where to put a code for it to turn off, and I’ve tried Debug.log and even that didn’t work. Any help is greatly appreciated. This below is my whole code on the player that allows it to collect the other pickup items and change the count.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class PlayerController2 : MonoBehaviour
{
public float speed;
public Text countText;
public Text winText;
private Rigidbody2D rb2d;
private int count;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
count = 0;
winText.text = "";
SetCountText();
}
void FixedUpdate(){
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
rb2d.AddForce(movement * speed);
}
void OnTriggerEnter2D(Collider2D other){
if (other.gameObject.CompareTag("PickUp")){
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
else if (other.gameObject.CompareTag("Rocket")){
other.gameObject.SetActive(false);
count += -2;
SetCountText();
}
if (other.gameObject.CompareTag("Star")){
other.gameObject.SetActive(false);
count = count + 3;
SetCountText();
}
if (other.gameObject.CompareTag("Wall")){
if (count >= 8) {
other.gameObject.SetActive(false);
}
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 15)
winText.text = "You beat level 2! Now to the final stage!";
if (count >= 15)
Invoke("ChangeLevel", 3.5f);
if (count <= -1)
Invoke("ChangeLevel2", 0f);
}
void ChangeLevel()
{
Application.LoadLevel("level3");
}
void ChangeLevel2()
{
Application.LoadLevel("lose");
}
}