ok so i was just trying to make a game where you push stuff of a platform and i need a variable for obstacle count that is on the main platform(there is 3 platforms, 1st main, 2nd teleportation platform, 3rd platform where all the teleported obstacles go) to make the level end when all the obstacles are pushed off, but when they are pushed off the variable number doesnt move. heres the code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class ButtonManager : MonoBehaviour
{
public GameObject StartScreen;
public GameObject LevelsScreen;
private ObstacleController obstacleController;
public TextMeshProUGUI obstacleCountText;
// Start is called before the first frame update
void Start()
{
StartScreen.gameObject.SetActive(true);
LevelsScreen.gameObject.SetActive(false);
obstacleCountText.gameObject.SetActive(false);
obstacleController = GameObject.Find("ObstacleController").GetComponent<ObstacleController>();
}
// Update is called once per frame
void Update()
{
obstacleCountUpdater();
}
// buttons
// Levels button
public void levelsScreen() {
StartScreen.gameObject.SetActive(false);
LevelsScreen.gameObject.SetActive(true);
obstacleCountText.gameObject.SetActive(false);
}
public void ExitLevelsScreenButton()
{
StartScreen.gameObject.SetActive(true);
LevelsScreen.gameObject.SetActive(false);
obstacleCountText.gameObject.SetActive(false);
}
public void lvl1()
{
LevelsScreen.gameObject.SetActive(false);
obstacleController.obstacleCount = 1;
obstacleCountText.gameObject.SetActive(true);
return;
}
public void obstacleCountUpdater()
{
obstacleCountText.text = "Obstacles :" + obstacleController.obstacleCount;
}
}
that was for the buttons and heres for the obstacles :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ObstacleController : MonoBehaviour
{
public float obstacleCount = 60;
public bool ObsatcleOnPlatform2 = false;
// Start is called before the first frame update
void Start()
{
obstacleCount = 0;
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("RespawnObstacle"))
{
transform.position = new Vector3(0f, -100, 11);
}
else if (other.gameObject.CompareTag("ObstaclesGround") && ObsatcleOnPlatform2)
{
obstacleCount = 3;
ObsatcleOnPlatform2 = false;
}
}
}
some one please help me.