'If statement in OnTriggerEnter function is not working properly
I can't understand this phenomenon now.
According to the c# code, count is added first, and the number of count is checked and the if statement is entered. (The reason that else is not used is that 1 and limitcount can be the same.) However, when actually executed, it is confirmed that count is 1 in the first trigger, but it does not enter the if statement. The second trigger returns 1 again, and after running Debug.log, the count is incremented to 2. What the problem is this?
private void OnTriggerEnter(Collider other)
{
if (other.GetComponentInParent<NHWTractor>() != null) {
if (other.GetComponentInParent<NHWTractor>().PV.IsMine)
{
count = count + 1;
Debug.Log(count.ToString());
if (count == 1)
{
fstRedCheck = redSign.activeSelf;
Debug.Log("first Check : "+ fstRedCheck.ToString());
}
if (count == limitCount)
{
scRedCheck = redSign.activeSelf;
Debug.Log("Light Check : " + scRedCheck.ToString());
if (fstRedCheck || scRedCheck)
other.GetComponentInParent<NHWTractor>().TrafficEvent();
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
