Trouble using collider2d.Istouching/istouchinglayers.
I am working on Unity 2018.2.12f1. It is a 2d Game and is been made for android platform. I have a part in the game where the player has to press/touch dig button(UI) to make way. So, in order to check whether the player is positioned at the right place for digging, I have tried using the is touching method of the collider. So basically the code contains col1.IsTouching(col2), where col1 is the player's capsule collider and col2 is the collider present at the digging site. Earlier I also tried the isTouchinglayers method and gave the layermask of the "player" layer. The problem is this very same code is working fine for the pc version of the game. But in the android version, the istouchinglayers was not working so I replaced with istouching and it was working. But the very next time i opened the same project it is not working again. So I am confused as to is it a bug or am I missing something. Hopefully my problem is clear, please let me know if you guys need any other details! Thanks!
Answer by Santosh_Nair · Oct 22, 2018 at 04:57 PM
For anyone stumbling onto this question. I got the problem resolved. The problem in my case was that I had the same script attached to multiple gameobjects in the same scene. And basically other instances of the script where overriding the variable's value of this script. So it was not responding to the collisions as true.
Your answer
Follow this Question
Related Questions
OverlapBox not working as expected 0 Answers
Physics 2D with tile collider corner problem 2 Answers
Had to turn off gravity scale, but now player goes through walls 0 Answers
Problem with hitboxes and hurtboxes 0 Answers
OverlapCircle not working correctly 0 Answers