I have reached this point in the series and when I run the game it randomly ends after some period of time. The ball remains stuck to the paddle and it doesn’t matter whether I move the mouse or not. How can i narrow down why this trigger event is being called?
Platform: Unity 5.5.2f1
I have added in a series of print statements and can confirm that the ball does indeed trigger the OnTriggerEnter2D event with a y axis that would trigger the event.
However, as you can see in the screen shot, the ball is right on the paddle and then jumps to the spot where the trigger is called.
I have checked the script execution order and it is set to Paddle[100], Ball[200]
The lose collier is set to be under the scene.
LoseCollier Script:
public class LoseCollider : MonoBehaviour {
public LevelManager levelmanager;
private void OnTriggerEnter2D(Collider2D collision)
{
print("Trigger: " + collision.name + " y:" + collision.transform.position.y);
levelmanager.LoadLevel("Win");
}
private void OnCollisionEnter2D(Collision2D collision)
{
print("Collision");
}
}
Level Manager
public class LevelManager : MonoBehaviour {
public void LoadLevel(string name)
{
Debug.Log ("Level load requested: " + name);
SceneManager.LoadScene(name);
}
public void QuitRequest()
{
Debug.Log("Quit");
Application.Quit();
}
}
And the ball
public class Ball : MonoBehaviour {
public Paddle thePaddle;
private Vector3 paddleToBallVector;
// Use this for initialization
void Start () {
paddleToBallVector = this.transform.position - thePaddle.transform.position;
print("Vector"+paddleToBallVector.ToString());
}
void Update () {
this.transform.position = thePaddle.transform.position + paddleToBallVector;
print("Ball: "+this.transform.position + " Paddle: " + thePaddle.transform.position);
}
}