Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Hàm waitforseconds trong C# Unity

22:23 17-01-2018 1.364 lượt xem 1 bình luận 09:39 18-01-2018

 

Mình đang tự học Unity, trong tutorial Space Shooter có đoạn code tạo Enemy, nhưng mình không hiểu lắm 3 dòng code cuối, nó để làm gì nhỉ?

yield return new WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y));
targetManeuver = 0;
yield return new WaitForSeconds (Random.Range (maneuverWait.x, maneuverWait.y));

biết rằng biến maneuverWait và maneuverTime là Vector2 mình sẽ nhập vào bằng tay trong Inspector.

 

	IEnumerator Evade()
	{
		yield return new WaitForSeconds (Random.Range (startWait.x, startWait.y));
		while (true)
		{
			if (target!=null)
			{
				targetManeuver = target.transform.position.x;
			}
			else
			{
				targetManeuver = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x);
			}
			yield return new WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y));
			targetManeuver = 0;
			yield return new WaitForSeconds (Random.Range (maneuverWait.x, maneuverWait.y));

		}
	}

 

 

 

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 09:39 18-01-2018

bản chấ t là bạn sẽ phải đợi hết khoảng thời gian ttrong yeild rồi mới chạy tiếp

Câu hỏi mới nhất