How to let player hit a boxcollider just once?(2D)
Hi guys,
So in my game the player hits the boxcollider2d and gets a point This happens but sometimes my player gets two points. So i'm thinking that it hits the boxcollider2d twice.
I used the following code: gameObject.SetActive(false);
but that stops the looping of my boxcolliders,so i dont want to use that.
I also made my boxcollider2d smaller but that doesnt prevent getting this. What can the problem be? It can't be that my computer is not fast enough to figure out what is happening.
(the player has one boxcollider2d)
Answer by SoloDeveloper · Dec 29, 2015 at 03:53 AM
Use OnTriggerEnter2D
Then disable it when hit so..
Void OnTriggerEnter2D (Collider2d col){
if(col.tag == "Player"){
col.GetComponent<YOURPOINTSCRIPT>().point +=1;
gameobject.SetActive(false);
}
}
make sure your point boxcollider is set to trigger
i get the error that says: 'Scores.score' is inaccessible due to its protection level. So my pointscript is inaccessible .
i dont know what to do now . if this doesnt work. is there there a way to disable the boxcollider2d for just a second?
in your "Scores" script add public in front of your score variable it so public score int/float;