Esempio n. 1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            //Check if movable and can move
            if (CheckMoves.CanMove(transform, (transform.position - other.transform.position).normalized))
            {
                GameManager.Instance.SaveCubePosition(transform, transform.position);

                Move(transform.position - other.transform.position);
            }
            //Or can be pushed and push
            else if (Pushable && CheckMoves.CanClimb(transform, (transform.position - other.transform.position).normalized))
            {
                GameManager.Instance.SaveCubePosition(transform, transform.position);

                PushUp(transform.position - other.transform.position);
            }
        }
    }
Esempio n. 2
0
    //Move a character on cooldown
    public void MoveChar(SwipeDirection dir)
    {
        if (moveCoolDown >= moveDuration)
        {
            //Pick direction instruction
            switch (dir)
            {
            case SwipeDirection.Up:
            {
                targetDir = Vector3.left;
                targetRot = new Vector3(0, -90f, 0);
                break;
            }

            case SwipeDirection.Down:
            {
                targetDir = Vector3.right;
                targetRot = new Vector3(0, 90f, 0);
                break;
            }

            case SwipeDirection.Left:
            {
                targetDir = Vector3.back;
                targetRot = new Vector3(0, -180f, 0);
                break;
            }

            case SwipeDirection.Right:
            {
                targetDir = Vector3.forward;
                targetRot = new Vector3(0, 0, 0);
                break;
            }

            case SwipeDirection.None:
                return;

            default:
                break;
            }



            //Move depending on switch instructions
            transform.eulerAngles = targetRot;


            //If player can Move
            if (!IsMoving && CheckMoves.CanMove(transform, targetDir, true))
            {
                //Debug.Log("MOVE");

                anim.SetTrigger("Move");
                moveCoolDown = 0f;

                GameManager.Instance.SaveCubePosition(transform, transform.position);

                StartCoroutine(StopMove(targetDir));
            }
            //Or can climb
            else if (!IsMoving && CheckMoves.CanClimb(transform, targetDir))
            {
                GameManager.Instance.SaveCubePosition(transform, transform.position);

                StartCoroutine(StopClimb(targetDir));
            }
        }
    }