zoukankan      html  css  js  c++  java
  • 士兵列阵

    using UnityEngine;
    using System.Collections;
    
    public class duilie : MonoBehaviour
    {
    
        object[] objs;
        public ArrayList DL;
        public void Start()
        {
            DL = new ArrayList();
            objs = GameObject.FindSceneObjectsOfType(typeof(Transform));
            foreach (Transform tr in objs)
            {
                if (tr.GetComponent<SphereCollider>())
                {
                    DL.Add(tr);
                }
            }
            Debug.Log((DL[0] as Transform).name);
            Debug.Log((DL[1] as Transform).name);
        }
    
        void Update()
        {
    
          
                
            
            if (Input.GetKeyDown(KeyCode.D))//一字长蛇阵
            {
                StopAllCoroutines();
                for (int i = 1; i < DL.Count; i++)
                {
                    GameObject obj = (DL[i] as Transform).gameObject;
                    Debug.Log(obj.name);
                    Vector3 _begin = obj.transform.position;
                    Vector3 _end = (DL[0] as Transform).position + new Vector3(2, 0, 0) * i;
                    StartCoroutine(Z_TWEEN.TweenPosition(obj, _begin, _end, 1));
                }
            }
    
            if (Input.GetKeyDown(KeyCode.F))//雁行阵
            {
                StopAllCoroutines();
                for (int i = 1; i <= DL.Count / 2; i++)
                {
                    GameObject obj_zuo = (DL[i] as Transform).gameObject;
                    GameObject obj_you = (DL[DL.Count - i] as Transform).gameObject;
    
                    Vector3 _begin1 = obj_zuo.transform.position;
                    Vector3 _end1 = (DL[0] as Transform).position + new Vector3(2, 2, 0) * i;
    
                    Vector3 _begin2 = obj_you.transform.position;
                    Vector3 _end2 = (DL[0] as Transform).position + new Vector3(2, -2, 0) * i;
    
                    StartCoroutine(Z_TWEEN.TweenPosition(obj_zuo, _begin1, _end1, 1));
                    StartCoroutine(Z_TWEEN.TweenPosition(obj_you, _begin2, _end2, 1));
    
                }
            }
            if (Input.GetKeyDown(KeyCode.A)) //龟甲阵
            {
                StopAllCoroutines();
                float jiaodu = 2*Mathf.PI / (DL.Count-1);
                Debug.Log(jiaodu);
                float x, y;
    
    
                for (int i = 1; i < DL.Count; i++)
                {
                    GameObject obj = (DL[i] as Transform).gameObject;
    
                    Vector3 _begin = obj.transform.position;
                    x = Mathf.Sin(jiaodu * (i-2)) * 5;
                    y = Mathf.Cos(jiaodu * (i-2)) * 5;
                    Vector3 _end = new Vector3(x, y, 0)+(DL[0]as Transform).position;
                    print(Mathf.Sin(-90f/3.1415926f));
                    StartCoroutine(Z_TWEEN.TweenPosition(obj, _begin, _end, 1));
                }
            }
            if (Input.GetKeyDown(KeyCode.S))//箭矢阵
            {
                StopAllCoroutines();
                for (int i = 1; i < DL.Count ; i++)
                {
                    if (i <= 2)
                    {
                        GameObject obj_zuo = (DL[i] as Transform).gameObject;
                        GameObject obj_you = (DL[DL.Count - i] as Transform).gameObject;
    
                        Vector3 _begin1 = obj_zuo.transform.position;
                        Vector3 _end1 = (DL[0] as Transform).position + new Vector3(1, 1, 0) * i;
    
                        Vector3 _begin2 = obj_you.transform.position;
                        Vector3 _end2 = (DL[0] as Transform).position + new Vector3(1, -1, 0) * i;
    
                        StartCoroutine(Z_TWEEN.TweenPosition(obj_zuo, _begin1, _end1, 1));
                        StartCoroutine(Z_TWEEN.TweenPosition(obj_you, _begin2, _end2, 1));
                    }
                    else if(i>2&&i<=DL.Count-3)
                    {
                        GameObject obj = (DL[i] as Transform).gameObject;
                        Debug.Log(obj.name);
                        Vector3 _begin = obj.transform.position;
                        Vector3 _end = (DL[0] as Transform).position + new Vector3(2, 0, 0) * (i-2);
                        StartCoroutine(Z_TWEEN.TweenPosition(obj, _begin, _end, 1));
                    }
                }  
            }
          
        }
    
    }
  • 相关阅读:
    k8s访问服务时,解析不了域名
    docker常用常用删除操作
    Linux_修改hosts
    java-深克隆和浅克隆
    Mybatis 中$与#的区别
    mysql-修改字段类型和修改字段名称
    HttpMessageNotReadableException(一)
    log4j2的环境变量使用
    Linux中修改环境变量及生效方法
    转!!mysql order by 中文排序
  • 原文地址:https://www.cnblogs.com/Feiyuzhu/p/5344693.html
Copyright © 2011-2022 走看看