//创建20个敌人脚本
using UnityEngine; using System.Collections; public class homework05_enemyCreator : MonoBehaviour { public Transform[] spawnPoints; public GameObject enemyPrefab; int count; // Use this for initialization void Start () { } void AnimationEventTrigger() { if(count<=20) { count++; GameObject enemy = GameObject.Instantiate(enemyPrefab); Transform point = spawnPoints[Random.Range(0, 3)]; enemy.transform.position = point.position; enemy.transform.forward = point.right; } } }
//子弹脚本
using UnityEngine; using System.Collections; public class homework05_01 : MonoBehaviour { public float speed = 10; public GameObject bulletPrefab; CharacterController controller; // Use this for initialization void Start () { controller = this.GetComponent<CharacterController>(); } // Update is called once per frame void Update () { float dx = Input.GetAxis("Horizontal"); controller.Move(transform.right * dx * speed * Time.deltaTime); if(Input.GetMouseButtonDown(0)) { GameObject go = Instantiate(bulletPrefab); go.transform.position = transform.position; go.transform.rotation = transform.rotation; go.GetComponent<Rigidbody>().velocity = transform.forward * 10; Destroy(go,3); } } }
//子弹击中敌人脚本
using UnityEngine; using System.Collections; public class homework05_01_bullet : MonoBehaviour { // Use this for initialization void Start () { } private void OnTriggerEnter(Collider other) { if(other.CompareTag("Enemy")) { other.GetComponent<homework05_01_enemy>().OnDead(); Destroy(gameObject); } } }
//游戏胜利与游戏结束脚本
using UnityEngine; using System.Collections; public class homework05_01_enemy : MonoBehaviour { public static int deadCount = 0; Animator anim; // Use this for initialization void Start () { anim = this.GetComponent<Animator>(); } private void OnTriggerEnter(Collider other) { if(other.CompareTag("Player")) { Debug.Log("游戏结束"); Time.timeScale = 0; } } //子弹调用的敌人死亡方法 public void OnDead() { anim.SetBool("dying", true); this.GetComponent<Collider>().enabled = false; Destroy(gameObject,3); deadCount++; if(deadCount>=20) { Debug.Log("游戏胜利"); } } }
因篇幅问题不能全部显示,请点此查看更多更全内容
怀疑对方AI换脸可以让对方摁鼻子 真人摁下去鼻子会变形
女子野生动物园下车狼悄悄靠近 后车司机按喇叭提醒
睡前玩8分钟手机身体兴奋1小时 还可能让你“变丑”
惊蛰为啥吃梨?倒春寒来不来就看惊蛰
男子高速犯困开智能驾驶出事故 60万刚买的奔驰严重损毁