Trigger FinishLine
So I'm working on a maze, My ball goes through the maze and I'm trying to make a finish line as a box as a collider with Is Trigger.
I created the object, box collider is checked, is trigger is checked.
I wrote a script, it compiles successfully.
I attach the script to the FinishPlane, create a gameobject > Ui > Text and then drag it into the text box labeled "Win Text" However the text is not triggered by the finish line.
Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FinishLine : MonoBehaviour {
public Text winText;
private bool FinishPlane = false;
// Use this for initialization
void Start () {
FinishPlane = false;
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "Player") {
FinishPlane = true;
winText.text="You Win!";
}
}
}
Answer by Ygedey · Feb 27, 2017 at 08:50 PM
Check the type of your player collider. Not all collider types generate trigger events when they collide. See the tables here for more info.
$$anonymous$$y player is just a sphere, if it helps, heres the script for my sphere. I was also wondering if i needed to combine the sphere and the finish line into one script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : $$anonymous$$onoBehaviour {
public float speed;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
}
Your answer
Follow this Question
Related Questions
ui Text not responding to collider 1 Answer
One textUI and two colliders that update it 0 Answers
Problem dealing with colliders in a complex project [SOLVED] 0 Answers
On trigger show text 1 Answer