public override void Update() { float distance; // vectorと移動先のpointsまでの距離 if (isUnderSomeone || isHit) { hasStarted = true; } // 点を順に辿る if (hasStarted && !hasEnded) { for (int i = 0; i < goingSegments.Length; i++) { if (goingSegments[i]) { Vector2 baseSpeed; if (i < goingSegments.Length - 1) { curPoint = points[i + 1]; speed = points[i + 1].position - points[i].position; baseSpeed = Vector2.Normalize(speed); baseSpeed *= new Vector2(stage.camera.speed.Length(), stage.camera.speed.Length()); speed = baseSpeed; position += speed; } else { hasEnded = true; break; } } distance = Vector2.Distance(position, curPoint.position); if (distance < 5) { goingSegments[i] = false; goingSegments[i + 1] = true; } } if (counter % 5 == 0) { if (!game.isMuted) { drivingSound.Play(SoundControl.volumeAll, 0f, 0f); } } counter++; } if (hasEnded) { speed = Vector2.Zero; } }
public override void Update() { float distance; // vectorと移動先のpointsまでの距離 if (isUnderSomeone || isHit) hasStarted = true; // 点を順に辿る if(hasStarted && !hasEnded) { for(int i=0;i<goingSegments.Length;i++) { if(goingSegments[i]) { Vector2 baseSpeed; if(i < goingSegments.Length-1) { curPoint = points[i+1]; speed = points[i+1].position - points[i].position; baseSpeed = Vector2.Normalize(speed); baseSpeed *= new Vector2(stage.camera.speed.Length(), stage.camera.speed.Length()); speed = baseSpeed; position += speed; } else { hasEnded = true; break; } } distance = Vector2.Distance(position, curPoint.position); if(distance < 5) { goingSegments[i] = false; goingSegments[i + 1] = true; } } if(counter % 5 == 0) { if (!game.isMuted ) drivingSound.Play(SoundControl.volumeAll, 0f, 0f); } counter++; } if (hasEnded) { speed = Vector2.Zero; } }