Пример #1
0
    // Update is called once per frame
    void Update()
    {
        horizontalMove = joyStick.GetHorizontalValue();
        verticalMove   = joyStick.GetVerticalValue();

        moveVec.Set(horizontalMove * cos45 - verticalMove * sin45, 0, horizontalMove * sin45 + verticalMove * cos45);
        moveVec = moveVec.normalized;

        if (Input.GetMouseButtonDown(1))
        {
            fsm.setState(EUnitState.RangeAtk);
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            fsm.setState(EUnitState.Attack1);
            return;
        }

        if (Mathf.Abs(horizontalMove) < Mathf.Epsilon && Mathf.Abs(verticalMove) < Mathf.Epsilon)
        {
            fsm.setState(EUnitState.Idle);
        }
        else
        {
            //move
            rigdBody.MovePosition(transform.position + moveVec * moveSpeed * Time.deltaTime);
            fsm.setState(EUnitState.Run);

            //Rotation
            Quaternion newRot = Quaternion.LookRotation(moveVec);
            rigdBody.MoveRotation(newRot);
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal");
        verticalMove   = Input.GetAxisRaw("Vertical");

        moveVec.Set(horizontalMove * cos45 - verticalMove * sin45, 0, horizontalMove * sin45 + verticalMove * cos45);
        moveVec = moveVec.normalized;

        if (Input.GetMouseButtonDown(0) && fsm.currentState != EUnitState.RangeAtk)
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1000f, 1 << 10))
            {
                transform.LookAt(hit.point);
            }

            fsm.setState(EUnitState.Attack1);
            return;
        }

        if (Input.GetMouseButtonDown(1) && fsm.currentState != EUnitState.Attack1)
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1000f, 1 << 10))
            {
                transform.LookAt(hit.point);
            }

            fsm.setState(EUnitState.RangeAtk);

            Bullet bullet = BulletMgr.Instance.PopBullet();

            Vector3 moveVec = transform.forward;    //이동방향 벡터

            //첫번째 Init인자는 시작위치,
            bullet.Init(transform.position + Vector3.up * 0.48f + moveVec * 0.3f,
                        moveVec, 8f, 20f, EBulletType.LINEAR, EBulletShooter.PLAYER); //Init으로 기본 속성 설정해줌

            return;
        }

        if ((int)fsm.currentState < 2)
        {
            if (Mathf.Abs(horizontalMove) < Mathf.Epsilon && Mathf.Abs(verticalMove) < Mathf.Epsilon)
            {
                fsm.setState(EUnitState.Idle);
            }
            else
            {
                //move
                rigdBody.MovePosition(transform.position + moveVec * moveSpeed * Time.deltaTime);
                fsm.setState(EUnitState.Run);

                //Rotation
                Quaternion newRot = Quaternion.LookRotation(moveVec);
                rigdBody.MoveRotation(newRot);
            }
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        if (camUpdate)
        {
            cam       = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
            camUpdate = false;
        }
        horizontalMove = Input.GetAxisRaw("Horizontal");
        verticalMove   = Input.GetAxisRaw("Vertical");

        moveVec.Set(horizontalMove * cos45 - verticalMove * sin45, 0, horizontalMove * sin45 + verticalMove * cos45);
        moveVec = moveVec.normalized;

        if (Input.GetMouseButtonDown(0) && fsm.currentState != EUnitState.RangeAtk)
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1000f, 1 << 10))
            {
                transform.LookAt(hit.point);
            }

            fsm.setState(EUnitState.Attack1);
            return;
        }

        if (Input.GetMouseButtonDown(1) && fsm.currentState != EUnitState.Attack1)
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1000f, 1 << 10))
            {
                transform.LookAt(hit.point);
            }

            fsm.setState(EUnitState.RangeAtk);

            Bullet bullet = BulletMgr.Instance.PopBullet();

            Vector3 moveVec = transform.forward;    //이동방향 벡터

            //첫번째 Init인자는 시작위치,
            bullet.Init(transform.position + Vector3.up * 0.48f + moveVec * 0.3f,
                        moveVec, 8f, 20f, EBulletType.LINEAR, EBulletShooter.PLAYER); //Init으로 기본 속성 설정해줌

            return;
        }

        if ((int)fsm.currentState < 2)
        {
            if (Mathf.Abs(horizontalMove) < Mathf.Epsilon && Mathf.Abs(verticalMove) < Mathf.Epsilon)
            {
                fsm.setState(EUnitState.Idle);
            }
            else
            {
                //move
                //rigdBody.MovePosition(transform.position + moveVec * moveSpeed * Time.deltaTime);
                Vector3 origin = transform.position;
                transform.position += moveVec * moveSpeed * Time.deltaTime;
                if (transform.position.x <= -13.0f || transform.position.x >= 13.0f)
                {
                    transform.position = new Vector3(origin.x, transform.position.y, transform.position.z);
                }
                if (transform.position.z >= 25.0f || transform.position.z <= 0.0f)
                {
                    transform.position = new Vector3(transform.position.x, transform.position.y, origin.z);
                }
                fsm.setState(EUnitState.Run);

                //Rotation
                //Quaternion newRot = Quaternion.LookRotation(moveVec);
                //rigdBody.MoveRotation(newRot);
                transform.forward = moveVec.normalized;
            }
        }
    }