zoukankan      html  css  js  c++  java
  • 程序代码

    using UnityEngine;
    using System.Collections;
    
    public class calDis : MonoBehaviour 
    {
    
        public GameObject closestAnt,orgi;//orgi is a base point      closeAnt is a sign
        public float  distance;
        public float  ttime=0;
        public GameObject[] gos;
        private GameObject next1,next2,next3,At1,At2,At3;
        private int i1,i2,i3;
        private bool sign=true;
        // Use this for initialization
        void Start () {
            
            orgi=GameObject.Find("Cube") ;    
            
            Debug.Log(orgi);
            
        }
        void Update(){
            ttime+=Time.deltaTime;
            if(ttime>=10f)
            {
              StartCoroutine("calculate");
              ttime=0f;
            }
        }
        IEnumerator calculate()
        {    
            
                    gos=GameObject.FindGameObjectsWithTag("Ant");
                    yield return StartCoroutine("search1",orgi) ; // one 
                    Debug.Log("gggggggggg1");
                    Debug.Log(At1.GetInstanceID());
                    StopCoroutine("search1");
                    yield return StartCoroutine("search2",At1);
                    Debug.Log("gggggggggg2");
                    Debug.Log(At2.GetInstanceID());
                    StopCoroutine("search2");
                    yield return StartCoroutine("search3",At2);
                    Debug.Log("gggggggggg3");
                    Debug.Log(At3.GetInstanceID());
                    StopCoroutine("search3");
        }
        
        //cal closest points A
        IEnumerator search1(GameObject clo)
        {
            distance=99999f;
            foreach(GameObject o in gos)
            {
                if(o!=clo)  //culling points
                {
                    float curdis=Vector3.Distance(clo.transform.position ,o.transform.position);
                    if(curdis<distance)
                    {
                        distance=curdis;
                        closestAnt=o;
                    }
                }
                
                    
            }
            //Debug.Log("Z");'
            At1=closestAnt;
            yield return closestAnt;
            
        }
        
        IEnumerator search2(GameObject clo)
        {
            distance=99999f;
            foreach(GameObject o in gos)
            {
                if(o!=clo&&o!=orgi)  //culling points
                {
                    float curdis=Vector3.Distance(clo.transform.position ,o.transform.position);
                    if(curdis<distance)
                    {
                        distance=curdis;
                        closestAnt=o;
                    }
                }
            }
            At2=closestAnt;
            yield return closestAnt;            
        }
        
        IEnumerator search3(GameObject clo) 
        {
            distance=99999f;
            bool findObject=false;
            foreach(GameObject o in gos)
           {
            if(o!=clo&&o!=orgi&&o!=At1) //culling points
             {
                    float curdis=Vector3.Distance(clo.transform.position ,o.transform.position);
                    if(curdis<distance)
                      {
                            distance=curdis;
                            closestAnt=o;
                            findObject=true;
                      }
             }
           }
            if(!findObject)
             { 
                yield return null;
                Debug.Log("no one for 3");
            }
            else
            {
            At3=closestAnt;
            Debug.Log("ddddd"+At3);
            yield return closestAnt;
            }
        }
        
        
        
        
     
    
    }
  • 相关阅读:
    System.InvalidOperationException异常的处理!vs15版
    五子棋项目的实现(四)具体的总结
    五子棋项目的实现(三)人机对战类的具体设计
    五子棋项目的实现(二)博弈树算法的描述
    五子棋项目的实现(一)
    java Exception和Error的区别
    java内存分配实例
    expdp与impdp
    SQL*PLUS下使用AUTOTRACE、sql顾问、实时sql监控
    Linux下如何将数据库脚本文件从sh格式变为sql格式
  • 原文地址:https://www.cnblogs.com/xiao-wei-wei/p/3424396.html
Copyright © 2011-2022 走看看