zoukankan      html  css  js  c++  java
  • bj

    using UnityEngine;
    using System.Collections;
    
    public class node : MonoBehaviour {
        public int index;
        public GameObject target;// 手按的物体
        public Vector3 v;
        public GameObject pre,obj;
        public GameObject closeobj;
        public GameObject[] gos;
        public createAnt ca;
        private float distance=99999;
        // Use this for initialization
        void Start () 
        {
            pre=GameObject.FindGameObjectWithTag("Cube");
            StartCoroutine(createAnts);
            if(Time.time>=10.0f)
            {
                StartCoroutine();
            }
        } 
       IEnumerator Cal()
        {
            gos=GameObject.FindGameObjectsWithTag("enemy");
            CalCulate();
            closeobj.AddComponent(); //加脚本
            
            
        }
        void CalCulate()
        {
            foreach (GameObject o in gos)
            {
                float curDis=Vector3.Distance(target.transform.position,o.transform.position);
                if(curDis<distance)
                {
                    distance=curDis;
                    closeobj=o;
                }
            }
            return closeobj;
        }
       IEnumerator createAnts()
        {
            InvokeRepeating("createant",1f,0.3f);
        }
        void createant()
        {
            v=new Vector3(Random.Range(0f,640f),Random.Range(0f,960f),0f);
            obj=Instantiate(pre,v,Random.rotation);
        }
        
    }
  • 相关阅读:
    LeetCode347 前k个高频元素
    剑指42 连续字数租的最大和
    hdu1540
    hdu4553 两棵线段树
    cdq分治
    负环
    最短路
    差分约束系统
    hdu3308
    hdu5862 树状数组+扫描线+离散化
  • 原文地址:https://www.cnblogs.com/xiao-wei-wei/p/3422461.html
Copyright © 2011-2022 走看看