六边形人物移动跳跃击打Combo下降逻辑

来源:互联网 发布:数据可视化工程师薪酬 编辑:程序博客网 时间:2024/06/03 22:08
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class HeroCtrolAR : MonoBehaviour {    public CellCtrol cellctrol;    public HeroStateAR myheroAR;    public GameObject point;    float angel_origin;    Animation animation;    bool can_walk = false;    bool is_jump = false;    bool is_UpAttack = true;//  攻击动画    bool isFromMoveing = false;//  移动后的抬起   public static bool VRCtrol=false;    //  UI    public Button btn_jump;    // Use this for initialization    void Start () {        cellctrol = transform.parent.GetComponent<CellCtrol>();        animation = transform.GetComponentInChildren<Animation>();        myheroAR = transform.GetComponent<HeroStateAR>();        transform.GetComponentInChildren<Animation>().wrapMode = WrapMode.Loop;        animation.CrossFade("Idle");        point = GameObject.Find("Point");        // UI        btn_jump = GameObject.Find("Canvas/btn_jump").GetComponent<Button>();        btn_jump.onClick.AddListener(OnButnPressUI);    }    float x, y,angle;    void OnEnable()    {        EasyJoystick.On_JoystickMove += OnJoystickMove;        EasyJoystick.On_JoystickMoveEnd += OnJoystickMoveEnd;        EasyButton.On_ButtonUp += OnButnPress;        EasyTouch.On_TouchUp += OnTouchUP;        EasyTouch.On_TouchDown += OnTouchDown;    }    // Unsubscribe      void OnDisable()    {        EasyJoystick.On_JoystickMove -= OnJoystickMove;        EasyJoystick.On_JoystickMoveEnd -= OnJoystickMoveEnd;        EasyButton.On_ButtonUp -= OnButnPress;        EasyTouch.On_TouchUp -= OnTouchUP;        EasyTouch.On_TouchDown -= OnTouchDown;    }    // Unsubscribe      void OnDestroy()    {        EasyJoystick.On_JoystickMove -= OnJoystickMove;        EasyJoystick.On_JoystickMoveEnd -= OnJoystickMoveEnd;        EasyButton.On_ButtonUp -= OnButnPress;        EasyTouch.On_TouchUp -= OnTouchUP;        EasyTouch.On_TouchDown -= OnTouchDown;    }    void OnTouchUP(Gesture gesture)    {        if (!gesture.isHoverReservedArea)        {            OnButnPressUI();        }    }    void OnTouchDown(Gesture gesture)    {       }    void OnButnPressUI()    {        if (!VRCtrol) return;        if ( !is_jump && !isFromMoveing &&!isUpAndCtrollerMove)        {            is_jump = true;            OnJumpStart();        }    }    void OnButnPress(string name)    {        Debug.Log("1111");        UIManager._instance.setGameStop();    }    float time_move = 0f;    void OnJoystickMove(MovingJoystick move) {        if ( move.joystickName!= "New joystick")        {            Debug.Log("out"); return;        }        x = move.joystickAxis.x;        y = move.joystickAxis.y;        angle = Mathf.Atan2(y, x) * Mathf.Rad2Deg;        time_move+=Time.deltaTime;        if (time_move > 0.4f) {            time_move = 0f;            StartCoroutine(ChooseAngle(angle));        }        isFromMoveing = true;    }    void OnJoystickMoveEnd(MovingJoystick move)    {        if (move.joystickName != "New joystick")        {            Debug.Log("out"); return;        }        time_move = 0f;        angle = Mathf.Atan2(y, x) * Mathf.Rad2Deg;        StartCoroutine( ChooseAngle(angle));        isFromMoveing = false;    }    IEnumerator ChooseAngle(float angle)    {        if (!VRCtrol) yield return new WaitForSeconds(1000000);        if (angle > 120f && angle < 180f && !is_jump)        {            if (cellctrol.go_left_top)            {                MoveTransform(cellctrol.go_left_top.transform);            }        }        if (angle > 60f && angle < 120f && !is_jump)        {            if (cellctrol.go_top)            {                MoveTransform(cellctrol.go_top.transform);            }        }        if (angle > 0f && angle < 60f && !is_jump)        {            if (cellctrol.go_right_top)            {                can_walk = false;                MoveTransform(cellctrol.go_right_top.transform);            }        }        if (angle > -180f && angle < -120f && !is_jump)        {            if (cellctrol.go_left_bottom)            {                can_walk = false;                MoveTransform(cellctrol.go_left_bottom.transform);            }        }        if (angle < -60f && angle > -120f && !is_jump)        {            if (cellctrol.go_bottom)            {                can_walk = false;                MoveTransform(cellctrol.go_bottom.transform);                //transform.localRotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(angel, 0, 0), Time.deltaTime * 3);            }        }        if (angle < 0f && angle > -60f && !is_jump)        {            if (cellctrol.go_right_bottom)            {                can_walk = false;                MoveTransform(cellctrol.go_right_bottom.transform);            }        }        yield return null;    }    // Update is called once per frame    void Update () {        #region Mouse        /*        if (Input.GetKeyDown(KeyCode.Q)  )        {            if (cellctrol.go_left_top)            {                can_walk = false;                MoveTransform(cellctrol.go_left_top.transform);            }        }        if (Input.GetKeyDown(KeyCode.W) )        {            if (cellctrol.go_top)            {                can_walk = false;                MoveTransform(cellctrol.go_top.transform);            }        }        if (Input.GetKeyDown(KeyCode.E) )        {            if (cellctrol.go_right_top)            {                can_walk = false;                MoveTransform(cellctrol.go_right_top.transform);            }        }        if (Input.GetKeyDown(KeyCode.A) )        {            if (cellctrol.go_left_bottom)            {                can_walk = false;                MoveTransform(cellctrol.go_left_bottom.transform);            }        }        if (Input.GetKeyDown(KeyCode.S) )        {            if (cellctrol.go_bottom)            {                can_walk = false;                MoveTransform(cellctrol.go_bottom.transform);                //transform.localRotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(angel, 0, 0), Time.deltaTime * 3);            }        }        if (Input.GetKeyDown(KeyCode.D) )        {            if (cellctrol.go_right_bottom)            {                can_walk = false;                MoveTransform(cellctrol.go_right_bottom.transform);            }        }        // 跳        if (Input.GetKeyDown(KeyCode.R) )        {            can_walk = false;            Vector3 v = transform.parent.position - point.transform.position;                       //iTween.MoveTo(gameObject,iTween.Hash("position",transform.position+v.normalized*1,"time",2, "onstart", "OnStart", "oncomplete", "OnComplete","name","up"));            //iTween.MoveTo(gameObject, iTween.Hash("position", new Vector3(transform.parent.position.x, transform.parent.position.y + 0.15f, transform.parent.position.z),"name","back", "delay",1, "time", 1, "onstart", "OnStart", "oncomplete", "OnComplete1", "easetype",iTween.EaseType.easeInCubic));//easeInCirc easeInCubic        }        */        #endregion        Debug.DrawLine(transform.position, point.transform.position, Color.red);       // Debug.Log("y:" + transform.localPosition.y);    }    //移动    void MoveTransform(Transform t,float height=0f)    {        //距离        float Dis = Vector3.Distance(transform.position, transform.parent.position);        if (Dis > 0.2f && !isCombo) return;        Debug.Log("Dis "+Dis);        transform.parent = t;        Vector3 pos_move = t.position - transform.position;        string aniNameFuc = isUpAndCtrollerMove ? "OnUpAndCtrolMove" : "OnStart";// 播放不同动画        height = isUpAndCtrollerMove ?  Dis : 0;        iTween.MoveTo(gameObject, iTween.Hash("position",new Vector3(t.position.x,t.position.y+height, t.position.z),"time",0.8f, "onstart", aniNameFuc, "oncomplete","OnComplete"));        Vector3 v = transform.parent.position - point.transform.position;        Vector3 left = Vector3.Cross(pos_move,v);        Vector3 newFroward = Vector3.Cross(v,left);        transform.rotation = Quaternion.LookRotation(newFroward, -point.transform.position + transform.parent.position);        isCombo = false;        cellctrol = transform.parent.GetComponent<CellCtrol>();    }    void OnStart()    {        animation.CrossFade("Walk");    }    void OnUpAndCtrolMove()    {        animation.CrossFade("fangun");    }    // 起跳动作    void OnJumpStart()    {        animation.CrossFade("qitiao");        Invoke("qitiao_walk",0.12f);    }    // 起跳位移    void qitiao_walk()    {        animation.CrossFade("Walk");        Vector3 v = transform.parent.position - point.transform.position;        iTween.MoveTo(gameObject, iTween.Hash("position", transform.position + v.normalized * 1.3f, "delay", 0f, "time", 2,            "oncomplete", "JumOnComplete", "name", "up", "easetype", iTween.EaseType.easeOutCirc));    }    // 下落    void JumOnComplete()    {        is_jump = true;        //  返回地面        iTween.MoveTo(gameObject, iTween.Hash("position", new Vector3(transform.parent.position.x, transform.parent.position.y + 0.0f, transform.parent.position.z), "delay", 0, "time", 1, "onstart", "OnStart",    "oncomplete", "BackToGround", "easetype", iTween.EaseType.easeInCirc));//easeInCirc easeInCubic    }    void OnComplete()    {        if (isUpAndCtrollerMove)        {            isUpAndCtrollerMove = false;            JumOnComplete();// 移过去下落            Debug.Log("fly walk...");        }        animation.CrossFade("Idle");    }    void BackToGround()    {         is_jump = false;        isFromMoveing = false;        animation.CrossFade("luodi");        Invoke("JumpOverIdle",0.2f);        is_UpAttack = true;        isUpAndCtrollerMove = false;    }    void JumpOverIdle()    {        animation.CrossFade("Idle");    }         private void OnTriggerEnter(Collider other)    {        Debug.Log(other.name+"= "+ myheroAR);                //  子弹击中        if (other.name.Contains("bullet"))        {            myheroAR.DecreaseLife(1);        }        // 碰到敌人       if(other.tag=="Monster_six")        {            iTween.Stop(gameObject);//StopByName            if (is_UpAttack)                animation.CrossFade("Attack1");            else                animation.CrossFade("Attack3");            StartCoroutine("PlayMonsterAni",other);            // 向上翻跟头            Invoke("upAndRotate",1.2f);            MonsterStateAR mAR = other.GetComponent<MonsterStateAR>();            mAR.OnDefead();// 伤害            //myheroAR.AddMoney(mAR.money);  等金币动画播放完        }    }    int num = 0,i=0;    int AttackNum = 0;    float time = 0f;    float time_end = 0f;    // 被击    IEnumerator PlayMonsterAni(Collider c)    {        yield return new WaitForSeconds(0.7f);        // 设置combo值        time = Time.realtimeSinceStartup;        if (time - time_end > 4f) {            AttackNum = 0;            Debug.Log("time " + time + "  time_end" + time_end + " " + (time - time_end));        }         else            AttackNum++;        time_end = time;     //   Debug.Log("time "+time+"  time_end"+time_end+" "+ (time - time_end));     if(AttackNum>0)        UIManager._instance.SetCombo(AttackNum);        if (c)        {             num = c.GetComponent<MonsterStateAR>().money / 10;            Debug.Log(num+"====");            StartCoroutine("CreateCoin",c);            if (is_UpAttack)                c.gameObject.GetComponentInChildren<Animation>().CrossFade("Attacked");            else                c.gameObject.GetComponentInChildren<Animation>().CrossFade("AttackedDown");        }    }    // 产生金币    IEnumerator CreateCoin(Collider g)    {        while (i < num)        {            MyPoolManager._instance.CreateG(g.transform);            yield return new WaitForSeconds(0.2f);            i++;        }        i = 0;        yield return null;    }    bool isUpAndCtrollerMove = false;    bool isCombo = false;    // 向上翻跟头    void upAndRotate()    {        isCombo = true;        isUpAndCtrollerMove = true;//空中移动临格        is_jump = false; //上翻可以移动        is_UpAttack = false;// 控制动画 // 详见815设计文档        animation.CrossFade("fangun");       // animation.wrapMode = WrapMode.Once;        Vector3 v = transform.parent.position - point.transform.position;        // 上跳         iTween.MoveTo(gameObject, iTween.Hash("position", transform.position + v.normalized * 0.6f, "delay", 0f, "time", 1.0f,            "oncomplete", "JumOnComplete", "name", "up", "easetype", iTween.EaseType.easeOutCirc));        //iTween.MoveTo(gameObject, iTween.Hash("position", new Vector3(transform.parent.position.x, transform.parent.position.y + 0f, transform.parent.position.z), "delay", 0, "time", 0.2f,        //        "onstart", "OnStart", "oncomplete", "BackToGround", "easetype", iTween.EaseType.easeInCubic));    }   }

原创粉丝点击