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);
        }
        
    }
  • 相关阅读:
    JSON.parse()与JSON.stringify()的区别
    响应式布局
    document.selection
    jQuery $.proxy() 方法
    <转> 键值表
    jquery-jqzoom 插件 用例
    jquery 笔记
    前端表单验证常用的15个JS正则表达式<转>
    css 问题解决
    <转>break与continue
  • 原文地址:https://www.cnblogs.com/xiao-wei-wei/p/3422461.html
Copyright © 2011-2022 走看看