士兵列阵 - -、

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));
                }
            }  
        }
      
    }

}

 

posted @ 2016-04-01 13:37  哎呦不能错喔  阅读(245)  评论(0编辑  收藏  举报