- Home /
Coullecting Item sometimes counts double
Hi, now i made my first gamedemo with unity and everything worked fine, except a problem with collecting items. I have an onTriggerEnter function that, when triggerd, counts the number of items the player found. The problem is, that while collecting the item, the function sometimes adds 1 and sometimes adds 2 to the score, and i didn`t manage to solve that problem yet. I assume that it has to do with some update function, so that the game runs to fast, and the onTriggerEnter function could not deal with it. The code for the function is simple, so i don`t think that`s the problem:
function OnTriggerEnter(other:Collider)
{
if (other.tag == "Artifact")
{
Destroy(other.gameObject);
ScoreManager.Artifacts += 1;
blink = true;
// var audio2 = GetComponent.<AudioSource>();
audio2.Play();
}
}
Maybe someone else had the same problem, or knows a solution? Any comment would be helpful!
You should say that as an answer then. It could help other people in the future who have the same problem.
Answer by sheiro · Jun 11, 2015 at 12:17 PM
Sorry, i found the problem. I`m using 2 Colliders, one as an trigger, the other for physics. My bad :/
Your answer
![](https://koobas.hobune.stream/wayback/20220613200852im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A few thinks I need for this game 0 Answers
Enable an area after a condition is met 2 Answers
score not updating 1 Answer
Stackable Inventory Item 1 Answer
Remove item from array 2 Answers