- Home /
OnTriggerEnter() is occasionally not occurred
I am making some kind of casual sport game with some rhythm-tap contents.
I tried to make a system of touching to decide what score you get for that trial.
A target pad comes down from top, and there is a "node". If you touch right in time(when the node is in the target area), it will gives you certain amount of score.
the dark green-white area is target, and the white line under red person is node.
I have named dark-green area "pass", light green area "good", and white area "perfect".
And I have created a code
using UnityEngine;
using System.Collections;
public class NodeCtrl : MonoBehaviour {
public GameMgr gameMgr;
public int score = 0;
void Awake(){
gameMgr = GameObject.Find ("GameMgr").GetComponent <GameMgr>();
}
void OnTriggerEnter(Collider coll){
if (coll.CompareTag ("PERFECT")) {
Debug.Log("perfect");
score += 1;
}
if (coll.CompareTag ("GOOD")) {
Debug.Log("good");
score += 1;
}
if (coll.CompareTag ("PASS")) {
Debug.Log("pass");
score += 1;
}
coll.enabled = false;
}
public void SendBackScore (){
Debug.Log (score);
//GameObject.Find ("GameMgr").GetComponent<GameMgr>().Call(score);
gameMgr.Call (score);
score = 0;
}
}
However the console log occasionally says that I have got "miss"(which is 0 of score) when appropriately matching the node into target area. It happens about once in 5~15 trials randomly. By checking with Debug.Log(), it seems like to be that the OnTriggerEnter() part of my code does not work properly.
What can I do for solving this?
Where's the code that prints "miss"? What part of this code checks that you tapped in time?
The code that prints miss comes from Call(int score) in other script. It basically prints out "perfect", "good", "pass", "miss" by the score in parameter: 3 for perfect, 2 for good, 1 for pass, and 0 for miss
Answer by KrabyGame · Jul 03, 2016 at 11:41 PM
I don't really understand when/how you get the "miss", but try to set "Collision Detection" to "Continuous" or "Continuous Dynamic" on the rigidbody. It often helps to prevent problems with collisions/collider.
it get miss when the target and node never matches if touched
I have tried both options for collision detection and the problem was still existing
Your answer
Follow this Question
Related Questions
Trigger Sound more than Once 0 Answers
How to disable player gravity 2 Answers
Enable Trigger On Trigger 1 Answer
transpoter not working! 1 Answer