# prg 5-7 箭頭產生並新增全域變數 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ArrowGenerator : MonoBehaviour { public GameObject arrowPrefab; float span = 1.0f; float delta = 0; public static int eat_steak=0; void Start() { } // Update is called once per frame void Update() { this.delta += Time.deltaTime; if (this.delta > this.span) { this.delta = 0; GameObject go = Instantiate(arrowPrefab) as GameObject; int px = Random.Range(-6,7); go.transform.position = new Vector3(px, 7, 0); } } }