Answer the question
In order to leave comments, you need to log in
Why doesn't SetActive always work?
When the object touches the collider with the tag, the game should stop, hide the pause button, and display the canvas with the buttons. But when you score 21 points and lose, then everything is done, except for the output of the canvas. What could be the problem?
using UnityEngine;
public class WatchAttack : MonoBehaviour
{
private float speed = 1;
private Vector2 watchDirection;
public GameObject watch;
public GameObject pauseButton;
public GameObject destroyPoint;
public GameObject gameOverWindow;
public GameObject sound;
public GameObject highScoreWindow;
public static int highScore = 0;
public GameObject watchTarget;
public Vector2 spawnerDirection;
public GameObject spawnPoint;
void Start()
{
gameOverWindow.SetActive(false);
watchDirection.y = watchTarget.transform.position.y;
watch.transform.position = watchDirection;
}
private void Update()
{
speed += 0.07f * Time.deltaTime;
transform.Translate(speed * watch.transform.position * Time.deltaTime, Space.World);
}
private void OnTriggerEnter2D(Collider2D collision)
{
gameOverWindow.SetActive(true);
pauseButton.SetActive(false);
Time.timeScale = 0f;
sound.GetComponent<AudioSource>().Pause();
if (highScore < WatchKiller.score)
{
highScore = WatchKiller.score;
PlayerPrefs.SetInt("High score", highScore);
}
else if (highScore >= WatchKiller.score)
{
highScore = PlayerPrefs.GetInt("High score");
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question