• Unity-3d Day04 自动出兵地图


    塔造兵的代码:有三个预设体,通过tag区分

    using UnityEngine;
    using System.Collections;
    
    public class NewbatScript : MonoBehaviour {
        float time = 0;
        public GameObject batmanpre0;
        public GameObject batmanpre1;
        public GameObject batmanpre2;
        public GameObject batman0;
        public GameObject batman1;
        public GameObject batman2;
        // Use this for initialization
        void Start () {
            
        }
        
        //Update is called once per frame
        void Update () {
            time += Time.deltaTime;
            if (time > 1) {
                batman0 = Instantiate(batmanpre0, new Vector3(20f, 1.2f, 17f), Quaternion.identity) as GameObject;
                batman1 = Instantiate(batmanpre1, new Vector3(17f, 1.2f, 17f), Quaternion.identity) as GameObject;
                batman2 = Instantiate(batmanpre2, new Vector3(17f, 1.2f, 20f), Quaternion.identity) as GameObject;
                time = 0;
            }
        }
    }

    兵分路和移动的代码:

    using UnityEngine;
    using System.Collections;
    
    public class BatmanScript : MonoBehaviour {
        public GameObject[,] tower = new GameObject[3, 4];
        public GameObject target;
        public int road;
        public int num;
        public GameObject home;
        // Use this for initialization
        void Start () {
            tower[0, 0] = GameObject.Find("Tower00");
            tower[0, 1] = GameObject.Find("Tower01");
            tower[0, 2] = GameObject.Find("Tower02");
            tower[0, 3] = GameObject.Find("Tower03");
            tower[1, 0] = GameObject.Find("Tower10");
            tower[1, 1] = GameObject.Find("Tower11");
            tower[1, 2] = GameObject.Find("Tower12");
            tower[1, 3] = GameObject.Find("Tower13");
            tower[2, 0] = GameObject.Find("Tower20");
            tower[2, 1] = GameObject.Find("Tower21");
            tower[2, 2] = GameObject.Find("Tower22");
            tower[2, 3] = GameObject.Find("Tower23");
            road = int.Parse(transform.tag);
            num = 0;
            target = tower[road, num];
            home = GameObject.Find("Home1");
        }
        // Update is called once per frame
        void Update () {
            if (Vector3.Distance(transform.position, target.transform.position) < 3)
            {
                if (num < 3)
                {
                    num += 1;
                    target = tower[road, num];
                }
                else {
                    target = GameObject.Find("Home1");
                }
            } 
    
            transform.LookAt(target.transform.position);
            transform.Translate(Vector3.forward/6);
    
            
        }
    
    }

    兵与对面水晶碰撞自动销毁:

    using UnityEngine;
    using System.Collections;
    
    public class Home1Script : MonoBehaviour {
        // Use this for initialization
        void Start () {
          
        }
        void OnCollisionEnter(Collision collision) {
            Destroy(collision.gameObject);
        }
        // Update is called once per frame
        void Update () {
        
        }
    }

    效果图:地图就是一个cube贴上的图片   吼吼  nice

  • 相关阅读:
    在为知笔记中使用JQuery
    解决Wireshark安装Npcap组件失败
    SSL/TLS抓包出现提示Ignored Unknown Record
    Metasploit中aggregator插件无法使用
    Metasploit运行环境内存不要低于2GB
    如何查看抓包文件所使用的捕获过滤器
    Nvidia的CUDA库现在恢复使用了
    Metasploit远程调用Nessus出错
    Nessus更新到8.3.0
    Kali Linux安装字典StarDict
  • 原文地址:https://www.cnblogs.com/little-sun/p/4370354.html
Copyright © 2020-2023  润新知