zoukankan      html  css  js  c++  java
  • 代码

    using UnityEngine;
    using System.Collections;
    
    public class Test : MonoBehaviour 
    {
        
        public GameObject pre;
        public GameObject obj;
        public GameObject node;//记录最近点
        public  GameObject sf ;//self
        private Vector3 v;
        private float time;
        public GameObject[] gos;
        //最近的物体
        private GameObject closeobj;
        private float distance=Mathf.Infinity;
        
        void Start () 
        {
            position=sf.transform.position;
            StartCoroutine(createAnt());
            if(Time.time>=10f)
            StartCoroutine(calculate());
        }
        
        IEnumerator createAnt () 
        {
            InvokeRepeating("initAnt",1f,0.5f);
            yield return new WaitForSeconds(0);
        }
        
        IEnumerator calculate()
        {
            node=calNearNote();
            node.AddComponent("distance");
            //node.GetComponent("distance").
        }
        void initAnt()
        {
            Debug.Log("dodo");
            v=new Vector3(Random.Range(0f,640f),Random.Range(0f,960f),0f);
            //obj=Instantiate(pre,v,Random.rotation);
        }
        // 找到最近的点
        GameObject  calNearNote()
        {
            gos=GameObject.FindGameObjectsWithTag("enemy");
            foreach(GameObject go in gos)
            {
                float curDistance=(go.transform.position-position).sqrMagnitude;
                if(curDistance<distance)
                {
                    closeobj=go;
                    distance=curDistance;
                }
            }
            return closeobj;
        }
        
    }
  • 相关阅读:
    Mac_Homebrew
    Python的路径引用
    OpenTSDB-Writing Data
    OpenTSDB介绍
    Git文件状态描述
    TCollector
    TEXT和BLOB区别
    MySQL索引与Index Condition Pushdown
    webService入门学习(一)
    redis学习笔记(一 基本操作)。
  • 原文地址:https://www.cnblogs.com/xiao-wei-wei/p/3422319.html
Copyright © 2011-2022 走看看