Exemple #1
0
    // Start is called before the first frame update
    void Awake()
    {
        PlayerTurnEnd = null;
        mySR          = GetComponent <SpriteRenderer>();
        time          = FindObjectOfType <Clock>().beatTime;
        myAnim        = GetComponent <Animator>();
        myAnim.SetFloat("Speed", (1f / (time / 2f)));
        MM = FindObjectOfType <MapMapper>();
        MI = new MainInput();
        MI.Enable();
        MI.Movement.Movment.performed += perf => {
            if (!moving)
            {
                moving = true;
                StartCoroutine(Move());
            }
        };
        MI.Movement.Attack.performed += perf =>
        {
            if (!attacking)
            {
                attacking = true;
                StartCoroutine(Attac());
            }
        };

        Clock.Beat += () => {
            if (!(moveDir.x != 0 && moveDir.y != 0) && moveDir != Vector2Int.zero && CurrentAction && MM.map[currentPos.x + moveDir.x, currentPos.y + moveDir.y].TType == TileType.Floor)
            {
                if (!mySR.flipX && moveDir.x < 0)
                {
                    mySR.flipX = true;
                }
                else if (mySR.flipX && moveDir.x > 0)
                {
                    mySR.flipX = false;
                }
                currentPos += moveDir;
                StartCoroutine(MoveToPosition(moveDir, time));
                firstBeat = false;
            }
            else if (!(attacDir.x != 0 && attacDir.y != 0) && attacDir != Vector2Int.zero && !CurrentAction && MM.map[currentPos.x + attacDir.x, currentPos.y + attacDir.y].TType == TileType.Floor)
            {
                if (!mySR.flipX && attacDir.x < 0)
                {
                    mySR.flipX = true;
                }
                else if (mySR.flipX && attacDir.x > 0)
                {
                    mySR.flipX = false;
                }
                firstBeat = false;
                StartCoroutine(Attack(attacDir));
            }
            if ((moveDir == Vector2Int.zero || MM.map[currentPos.x + moveDir.x, currentPos.y + moveDir.y].TType != TileType.Floor) && movementEnded)
            {
                myAnim.SetBool("Move", false);
            }
            //Debug.Log("Move : " + moveDir);
            Debug.DrawLine(new Vector3(4, 4, 0), new Vector3(5, 5, 0), Color.red, 0.1f);
        };
        StartCoroutine(danceCheck());
    }
 private void Awake()
 {
     input = new MainInput();
     input.Enable();
 }