void Start()
    {
        int moveActionCount = 2;

        marcoMoveActions    = new RetVoidTakeVoid[moveActionCount];
        marcoMoveActions[0] = () => { marcoMove.HorizontalMovement(Vector2.right); };
        marcoMoveActions[1] = () => { marcoMove.HorizontalMovement(Vector2.left); };
        //marcoMoveActions[2] = marcoMove.LookUp;
        //marcoMoveActions[3] = marcoMove.DownMovement;
        marcoMoveAction = marcoMoveActions[0];

        marcoAttackActions    = new RetVoidTakeVoid[2];
        marcoAttackActions[0] = () => { marcoAttack.PrimaryAttack(); };
        marcoAttackActions[1] = () => { marcoAttack.SecondaryAttack(); };
        marcoAttackAction     = marcoAttackActions[0];

        int actionIndex = 0;

        timeUtils.RepeatEvery(2, () => {
            marcoMoveAction   = marcoMoveActions[actionIndex];
            marcoAttackAction = marcoAttackActions[actionIndex];
            marcoJump.Jump();
            marcoAttackAction();

            actionIndex = (actionIndex + 1) % marcoMoveActions.Length;
            return(true);
        });
    }
示例#2
0
    void Update()
    {
        bool jump;
        bool fireKey;
        bool grenadeKey;

        int horizontalKey = 0;
        int verticalKey   = 0;

#if UNITY_ANDROID || UNITY_IOS
        jump          = CnInputManager.GetButtonDown("Jump");
        fireKey       = CnInputManager.GetButtonDown("Fire1");
        grenadeKey    = CnInputManager.GetButtonDown("Fire2");
        horizontalKey = (int)CnInputManager.GetAxisRaw("Horizontal");
        verticalKey   = (int)CnInputManager.GetAxis("Vertical");
#else
        jump          = Input.GetButtonDown("Jump");
        fireKey       = Input.GetButtonDown("Fire1");
        grenadeKey    = Input.GetButtonDown("Fire2");
        horizontalKey = (int)Input.GetAxisRaw("Horizontal");
        verticalKey   = (int)Input.GetAxis("Vertical");
#endif

        if (fireKey)
        {
            attackManager.PrimaryAttack();
        }
        else if (grenadeKey)
        {
            attackManager.SecondaryAttack();
        }

        if (horizontalKey < 0)
        {
            movementManager.HorizontalMovement(Vector3.left);
        }
        else if (horizontalKey == 0)     //fix problem when changing direction (press right before releasing left)
        {
            movementManager.StopMoving();
        }
        else if (horizontalKey > 0)
        {
            movementManager.HorizontalMovement(Vector3.right);
        }

        if (verticalKey > 0)
        {
            movementManager.LookUp();
        }
        else if (verticalKey == 0)
        {
            movementManager.DefaultBodyPosition();
        }
        else if (verticalKey < 0)
        {
            movementManager.DownMovement();
        }

        if (jump)
        {
            movementManager.Jump();
        }

        if (Input.anyKeyDown)
        {
            CancelInvoke();
            InvokeRepeating("SendPlayerInactiveEvent", 5, 2);
        }
    }