void Update() { if (queryInt.getRound() <= 3) { userInt.emitDisk(); if (queryInt.isShooting()) { winText.text = ""; } if (queryInt.isShooting() && Input.GetMouseButtonDown(0) && Time.time > nextFireTime) { nextFireTime = Time.time + fireRate; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bullet.GetComponent <Rigidbody>().velocity = Vector3.zero; bullet.GetComponent <Rigidbody>().position = transform.position; bullet.GetComponent <Rigidbody>().AddForce(ray.direction * speed, ForceMode.Impulse); RaycastHit hit; if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "disk") { hit.collider.gameObject.SetActive(false); } } } else { winText.text = "You Win"; } roundText.text = "Round: " + queryInt.getRound().ToString(); scoreText.text = "Score: " + queryInt.getPoint().ToString(); if (round != queryInt.getRound()) { round = queryInt.getRound(); winText.text = "Round " + round.ToString(); } }
void Update() { if (queryInt.isCounting()) { // 显示倒计时 mainText.text = queryInt.getEmitTime().ToString(); } else { if (Input.GetKeyDown("space")) { userInt.emitDisk(); // 发射飞碟 } if (queryInt.isShooting()) { mainText.text = ""; // 射击开始,隐藏主提示 } // 发射子弹 if (queryInt.isShooting() && Input.GetMouseButtonDown(0) && Time.time > nextFireTime) { nextFireTime = Time.time + fireRate; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // 摄像机到鼠标射线 bullet.GetComponent <Rigidbody>().velocity = Vector3.zero; // 子弹刚体速度重置 bullet.transform.position = transform.position; // 子弹从摄像机位置射出 bullet.GetComponent <Rigidbody>().AddForce(ray.direction * speed, ForceMode.Impulse); RaycastHit hit; if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Disk") { // 播放爆炸粒子特效 explosion.transform.position = hit.collider.gameObject.transform.position; explosion.GetComponent <Renderer>().material.color = hit.collider.gameObject.GetComponent <Renderer>().material.color; explosion.Play(); // 击中飞碟设置为不活跃,自动回收 hit.collider.gameObject.SetActive(false); } } } roundText.text = "Round: " + queryInt.getRound().ToString(); scoreText.text = "Score: " + queryInt.getPoint().ToString(); // 如果回合更新,主提示显示新回合 if (round != queryInt.getRound()) { round = queryInt.getRound(); mainText.text = "Round " + round.ToString() + " !"; } }
void Update() { if (queryInt.isCounting()) { mainText.text = ((int)queryInt.getEmitTime()).ToString(); } else { if (Input.GetKeyDown("space")) { userInt.emitDisk(); } if (queryInt.isShooting()) { mainText.text = ""; } if (queryInt.isShooting() && Input.GetMouseButtonDown(0) && Time .time > nextFireTime) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bullet.GetComponent <Rigidbody>().velocity = Vector3.zero; bullet.transform.position = transform.position; bullet.GetComponent <Rigidbody>().AddForce(ray.direction * speed, ForceMode.Impulse); RaycastHit hit; if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Disk") { explosion.transform.position = transform.position; explosion.GetComponent <Renderer>().material = hit.collider.gameObject.GetComponent <Renderer>().material; explosion.GetComponent <ParticleSystem> ().Play(); hit.collider.gameObject.SetActive(false); } } } roundText.text = "ROUND: " + queryInt.getRound().ToString(); scoreText.text = "SCORE: " + queryInt.getPoint().ToString(); if (round != queryInt.getRound()) { round = queryInt.getRound(); mainText.text = "ROUND " + round.ToString() + "!"; } }
void Update() { if (Input.GetKeyDown("space")) { userInt.emitDisk(); } if (queryInt.isShooting()) { mainText.text = ""; } if (queryInt.isShooting() && Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bullet.GetComponent <Rigidbody>().velocity = Vector3.zero; bullet.transform.position = transform.position; bullet.GetComponent <Rigidbody>().AddForce( ray.direction * speed, ForceMode.Impulse); RaycastHit hit; if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Disk") { explosion.transform.position = hit.collider.gameObject.transform.position; explosion.GetComponent <Renderer>().material.color = hit.collider.gameObject.GetComponent <Renderer>().material.color; explosion.Play(); hit.collider.gameObject.SetActive(false); } } roundText.text = "Round: " + queryInt.getRound().ToString(); scoreText.text = "Score: " + queryInt.getPoint().ToString(); if (round != queryInt.getRound()) { round = queryInt.getRound(); mainText.text = "空格键发射"; } }