- Home /
Question by
zann06 · Apr 21, 2020 at 07:19 PM ·
multiplayerphotontimetimertimer countdown
time synchronization via Photon
Hi there! I have 2 teams A and B. There is also a zone on the map, if you get into it (only to one team), then the timer decreases from 10 seconds and when the value is 0, a certain action occurs. This zone works through OnTriggerStay. I have difficulties with this: When one player enters this zone, then everything is ok, the timer tends from 10 seconds to 0 at normal speed, BUT, when another player comes in from the same team, then the timer passes twice as fast.
Piece of code:
private double _timeToNewScore = 10f;
private double _time;
private void OnTriggerStay(Collider other) { if (hasCapturedOne) { foreach (Health p in team1players) { ScorePointsFromPeriod(1); }
private void ScorePointsFromPeriod(int team)
{
_time += Time.deltaTime;
if (_time >= _timeToNewScore)
{
DoSomething();
}
}
Please, help me)
Comment
Best Answer
Answer by bombombambam · Apr 21, 2020 at 07:56 PM
bool isOccupied;
void OnTriggerEnter(Collider other)
{
isOccupied = true;
}
void OnTriggerExit(Collider other)
{
isOccupied = false;
}
void Update()
{
if(isOccupied)
{
_time += Time.deltaTime;
if (_time >= _timeToNewScore)
{
DoSomething();
}
}
}