My trigger won't activate the UI when the player collides with it.
Hi, I'm trying to make my first simple game after months of doing tutorials.
My plan was to make a 2D game where the player is a ball that moves right to left and jumps up platforms to the top.
I've gotten stuck/pissed off. I'll continue searching for a way to fix this but if someone responds I will be grateful.
The problem is that when the player reaches the platform at the top, rather than the trigger activating the UI, it does nothing. What should happen is the UI comes on screen to say "you win!" After this would be done I was going to add a restart and quite game button but I'm stuck with this problem. :(
I will post screen shots and the player script and the game controller script.
Player script using UnityEngine; using System.Collections; using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public float speed;
public bool jump = false;
public float jumpForce = 8.0f;
public GameObject GameController;
public Transform groundCheck;
private bool grounded = false;
private Rigidbody2D rb2d;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
void OnCollisionEnter2D(Collision2D hit)
{
grounded = true;
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxisRaw("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
rb2d.AddForce(movement * speed);
}
void Update ()
{
if (Input.GetButtonDown("Jump"))
{
rb2d.AddForce(Vector2.up * jumpForce);
}
}
}
game controller
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GameController : MonoBehaviour {
public GameObject gameOverPanel;
public Text gameOverText;
void Start ()
{
gameOverPanel.SetActive(false);
}
void Update ()
{
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Exit")
{
gameOverPanel.SetActive(true);
// enabled = false;
}
}
// void GameOver ()
// {
//
//gameOverPanel.SetActive(true); //
// }
}
Your answer
Follow this Question
Related Questions
PLAYER NOT ACTIVATING TRIGGER WHEN ON TOP OF THE COLLIDER! IS THIS A BUG 0 Answers
Trigger is not detecting tag 2 Answers
Apply more damage over time?,How can I apply more damage over time? 0 Answers
Trigger FinishLine 1 Answer
Trigger issues 1 Answer