Question by
GuayDarth · Jan 20, 2018 at 04:41 PM ·
triggerscollisions
Frogger Logs OnTriggerEnter2D OnTriggerExit2D
I´m making a 2D Frogger game, and I´m having a problem with the tree logs above the water. When the frog crosses two logs above a certain speed, my script calls the OnTriggerEnter2D of the second log before the OnTriggerExit2D of the first log, causing the frog to die because of certain conditions I have in other scripts.
This is my LogBehaviour script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LogBehaviour : MonoBehaviour {
Vector2 velocity;
void Start () {
velocity = GetComponent<Rigidbody2D>().velocity;
}
void OnTriggerEnter2D(Collider2D col)
{
GameObject go = col.gameObject;
if(go.CompareTag("Player"))
{
go.GetComponent<PlayerController>().OnLog(this, velocity);
}
}
void OnTriggerExit2D(Collider2D col)
{
GameObject go = col.gameObject;
if (go.CompareTag("Player"))
{
go.GetComponent<PlayerController>().LeaveLog(this);
}
}
Comment
Your answer
Follow this Question
Related Questions
Using OnTriggerStay for entering, staying or exiting 2 Answers
Moving to Next Level on collision 1 Answer
Pipe Game ... I have to trace water from source to destination 2 Answers
When is OnTriggerExit2D called? 1 Answer
Can I know which exactly of an object's collider resulted in OnTriggerEnter()? 0 Answers