士兵列阵 - -、

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

}

 

转载于:https://www.cnblogs.com/Feiyuzhu/p/5344693.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值