Move() 공개 메소드

public Move ( GameObject dest ) : void
dest GameObject
리턴 void
예제 #1
0
    void Update()
    {
        //  _direction = _target.transform.position.x - transform.position.x;
        if (_Triggergate.isTrigger)
        {
            Debug.Log(_Triggergate.isTrigger);
            return;
        }
        if (Vector2.Distance(transform.position, _target.position) > 3)
        {
            animatorenemy.SetBool("isRunning", true);
            if ((_target.transform.position.x - transform.position.x < 0) && (_target.transform.position.y == transform.position.y))
            {
                _enemycontroll.Move(-1);
            }
            else if ((_target.transform.position.x - transform.position.x > 0) && (_target.transform.position.y == transform.position.y))
            {
                _enemycontroll.Move(1);
            }
            else if ((_target.transform.position.y < transform.position.y) && (!_enemycontroll.jumpstatus))
            {
                if (Vector2.Distance(transform.position, _points[0].transform.position) > Vector2.Distance(transform.position, _points[1].transform.position))
                {
                    _enemycontroll.Move(1);
                }
                else if (Vector2.Distance(transform.position, _points[0].transform.position) < Vector2.Distance(transform.position, _points[1].transform.position))
                {
                    _enemycontroll.Move(-1);
                }
            }
            else if ((_target.transform.position.y > transform.position.y) && (!_enemycontroll.jumpstatus))
            {
                animatorenemy.SetBool("isRunning", false);
                if ((Vector2.Distance(transform.position, _points[0].transform.position) > Vector2.Distance(transform.position, _points[1].transform.position)) && (!_enemycontroll.jumpstatus))
                {
                    transform.position = Vector2.MoveTowards(transform.position, _points[1].transform.position, _enemycontroll.speed * Time.deltaTime);
                }
                else if ((Vector2.Distance(transform.position, _points[0].transform.position) < Vector2.Distance(transform.position, _points[1].transform.position)) && (!_enemycontroll.jumpstatus))
                {
                    transform.position = Vector2.MoveTowards(transform.position, _points[0].transform.position, _enemycontroll.speed * Time.deltaTime);
                }
            }

            //transform.position = Vector2.MoveTowards(transform.position, _target.position, _enemycontroll._speed * Time.deltaTime);
            _enemycontroll.Flip();
        }

        Debug.Log(_Triggergate.isTrigger);
        //_enemycontroll.Move(1f);
        // _enemycontroll.Flip();
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (logic.IsEndOfGame || logic.IsCurrentPlayerAI || logic.IsAnimationOn)
        {
            return;
        }

        if (Input.GetKeyUp(KeyCode.B))
        {
            unitController.SettlerCommand();
        }


        if (!EventSystem.current.IsPointerOverGameObject())
        {
            if (Input.GetMouseButtonDown(0))
            {
                clicked++;
                if (clicked == 1)
                {
                    clicktime = Time.time;
                }
                else if (clicked > 1 && Time.time - clicktime < clickdelay)
                {
                    clicked       = 0;
                    clicktime     = 0;
                    isDoubleClick = true;
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                if (!isDoubleClick)
                {
                    cityController.Unselect();
                    resourceController.Unselect();
                    unitController.Select();
                }
                else
                {
                    unitController.Unselect();
                    cityController.Select();
                    resourceController.Select();
                }

                isDoubleClick = false;
            }
            else if (Input.GetMouseButtonUp(1))
            {
                unitController.Move();
            }
        }


        if (Time.time - clicktime >= clickdelay)
        {
            clicked   = 0;
            clicktime = 0;
        }
    }
        private void Move(Vector2 direction)
        {
            var running = UnityEngine.Input.GetKey(KeyCode.LeftShift);
            var speed   = running ? m_UnitController.runSpeed : m_UnitController.walkSpeed;

            m_UnitController.Move(direction * speed);
        }
예제 #4
0
    public void MoveMe(int x, int y)
    {
        cTile.RemoveUnit(unit);
        RemoveVision(this.x, this.y, visionRange);
        this.x = x;
        this.y = y;

        cTile = MapController.Instance.cMap[this.x, this.y];
        cTile.AddUnit(unit);
        unit.Move(this.x, this.y);
        CreateVision(this.x, this.y, visionRange);
    }
예제 #5
0
        void FixedUpdate()
        {
            if (m_Unit.m_NavMeshAgent.isStopped)
            {
                return;
            }

            switch (m_State)
            {
            case PlayerState.Idle:
                CheckNewAction();
                break;

            case PlayerState.Moving:
                m_Unit.Move(m_LastHit.point);
                CheckNewAction();
                if (m_Unit.HasArrived())
                {
                    m_State = PlayerState.Idle;
                }
                break;

            case PlayerState.MovingWithinRange:
                m_Unit.Move(m_LastHit.point);
                CheckNewAction();
                if (m_Combatant.IsInRange())
                {
                    m_State = PlayerState.Attacking;
                }
                break;

            case PlayerState.Attacking:
                m_Unit.Stop();
                StartCoroutine(m_Combatant.Attack());
                break;
            }
        }
예제 #6
0
    void FixedUpdate()
    {
        if (!m_enabled)
        {
            return;
        }

        // Get a list of all colliders in a radius.
        LayerMask layerMask = 1 << LayerMask.NameToLayer("Capsule");

        Collider[] colldiers = Physics.OverlapSphere(transform.position, 32.0f, layerMask);

        // Get the closest collider.
        GameObject closestCollider    = null;
        float      closestDistanceSqr = float.MaxValue;

        foreach (Collider colldier in colldiers)
        {
            // Ignore self.
            if (colldier == m_collider)
            {
                continue;
            }

            // Check distance to a collider.
            float distanceSqr = (colldier.transform.position - transform.position).sqrMagnitude;

            if (distanceSqr < closestDistanceSqr)
            {
                closestCollider    = colldier.gameObject;
                closestDistanceSqr = distanceSqr;
            }
        }

        // Look at the direction of the closest unit.
        if (closestCollider != null)
        {
            Vector3 offset = closestCollider.transform.position - m_collider.transform.position;

            if (closestDistanceSqr > 8.0f * 8.0f)
            {
                m_unitController.Move(offset.normalized);
            }
            else
            {
                m_unitController.Shoot(offset.normalized);
            }
        }
    }
    private void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Ray        ray = myCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            //checks if raycast hit an object in the units layer mask to deselect units
            if (!Physics.Raycast(ray, out hit, 100, unitMask))
            {
                RemoveUnit(0, unitsSize);
            }
            else
            {
                GameObject unit = hit.collider.gameObject;

                if (unit.GetComponent <Unit>().player == player)
                {
                    AddUnit(unit);
                }
            }
        }

        //issues order to current units
        if (Input.GetButtonDown("Fire2"))
        {
            Ray        ray = myCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            //checks if raycast hit a terrain object in the terrain layer mask
            if (Physics.Raycast(ray, out hit, 100, terrainMask))
            {
                //Debug info.
                //Debug.Log("Hit: " + hit.collider.name + ", Position: " + hit.point);

                foreach (GameObject unit in units)
                {
                    if (unit != null)
                    {
                        UnitController controller = unit.GetComponent <UnitController>();

                        /* Add additional orders for the player to issue.
                         */
                        controller.Move(hit.point);
                    }
                }
            }
        }
    }
    void FixedUpdate()
    {
        if (Time.time < inputWait)
        {
            return;
        }

        if (selectingMovement && Input.GetMouseButtonDown(0))
        {
            var point = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition);
            var grid  = GameManager.Instance.World2Grid(point);
            currentUnit.Move(grid);
            GridDisplay.SetActive(false);
            selectingMovement = false;
        }
    }
    void Update()
    {
        // Get the camera transform.
        Transform cameraTransform = m_cameraController.m_playerCamera.transform;

        // Calculate movement direction from user input.
        Vector3 direction = new Vector3();

        direction.x = Input.GetAxis("Horizontal");
        direction.z = Input.GetAxis("Vertical");
        direction.Normalize();

        // Calculate camera rotation around y-axis.
        Quaternion cameraRotation = Quaternion.Euler(0.0f, m_cameraController.m_rotation.y, 0.0f);

        // Make the player move in a direction relative to the camera.
        m_unitController.Move(cameraRotation * direction);

        // Make the player look in the camera direction.
        m_unitController.Look(cameraTransform.forward);

        // Make the player character jump on key press.
        if (Input.GetKey(KeyCode.Space))
        {
            m_unitController.Jump();
        }

        // Make the player character fire on key press.
        if (Input.GetKey(KeyCode.Mouse0))
        {
            // Calculate the point at which we want to fire at for the 3rd person mode.
            RaycastHit hitResult;
            if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out hitResult, Mathf.Infinity))
            {
                Vector3 shootSource = m_unit.transform.position + m_unitController.m_shootOrigin;
                m_unitController.Shoot(Vector3.Normalize(hitResult.point - shootSource));
            }
            else
            {
                Vector3 cameraTarget = cameraTransform.position + cameraTransform.forward * 100.0f;
                Vector3 shootSource  = m_unit.transform.position + m_unitController.m_shootOrigin;
                m_unitController.Shoot(Vector3.Normalize(cameraTarget - shootSource));
            }
        }
    }
예제 #10
0
 void RightMouseClick()
 {
     if (Input.mousePosition.y > mouseYLowerBound && !Input.GetKey(KeyCode.LeftControl))
     {
         Debug.Log("SelectorScript: RightMouseClick: selectedIndex: " + selectedIndex, this.gameObject);
         GameObject hitObject = FindHitObject();
         Vector3    hitPoint  = FindHitPoint();
         if (hitObject && hitObject.tag == "Terrain" && hitPoint != -Vector3.one && selectedIndex > 0)
         {
             for (int i = 0; i < selectedIndex; i++)
             {
                 UnitController unit = selectedObjects [i].GetComponent <UnitController> ();
                 if (unit)
                 {
                     Debug.Log("SelectorScript: RightMouseClick: moving object: " + selectedObjects [i].name, selectedObjects [i]);
                     unit.Move(hitPoint);
                 }
             }
         }
     }
 }
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (OnOffMenu)
            {
                _pc.escMenu.gameObject.SetActive(true);
                OnOffMenu = !OnOffMenu;
            }
            else
            {
                _pc.escMenu.gameObject.SetActive(false);
                OnOffMenu = !OnOffMenu;
            }
        }
        if (_pc.staminarecovery)
        {
            _pc.stamina.fillAmount = _pc.stamina.fillAmount + Time.deltaTime;
        }

        if (Input.GetKeyDown(KeyCode.Y))
        {
            Instantiate(_enemy, transform.position, Quaternion.identity);
        }

        var axis = Input.GetAxis("Horizontal");

        if (Mathf.Abs(axis) > 0.01f)
        {
            if (_pc.attacking)
            {
                return;
            }
            _pc.Move(axis);
            _pc.Flip();

            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                if (_staminabar.fillAmount > _dodgevalue)
                {
                    animationcharacter.SetTrigger("Dodge");
                }
                else
                {
                    animationcharacter.SetTrigger("Idle");
                }
            }
            if (_pc.isGrounded)
            {
                animationcharacter.SetBool("isRunning", true);
            }
        }
        else
        {
            if (Input.GetKeyUp(KeyCode.A) || (Input.GetKeyUp(KeyCode.D)))
            {
                _pc.Move(0);
                _pc.Flip();
                if (!_pc.isGrounded)
                {
                    return;
                }
                if (_pc.isGrounded)
                {
                    animationcharacter.SetBool("isRunning", true);
                }
            }
            else
            {
                animationcharacter.SetBool("isRunning", false);
            }
        }

        if ((Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.Space)))
        {
            if (_pc.attacking)
            {
                return;
            }
            if (_staminabar.fillAmount > _jumpvalue)
            {
                _pc.Jump();
                animationcharacter.SetBool("isFalling", false);
                animationcharacter.SetBool("isJumping", true);
                if (_pc.extraJump > 0)
                {
                    _staminabar.fillAmount -= _jumpvalue;
                    _firstjump              = true;
                    _pc.CooldownStamina();
                }
                else if ((_pc.extraJump == 0) && (_firstjump))
                {
                    _staminabar.fillAmount -= _jumpvalue;
                    _firstjump              = false;
                    _pc.CooldownStamina();
                }
            }
        }
        else
        {
            if (!_pc.isGrounded)
            {
                animationcharacter.SetBool("isFalling", true);
            }
            if (_pc.isGrounded)
            {
                animationcharacter.SetBool("isJumping", false);
                animationcharacter.SetBool("isFalling", false);
            }
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            _pc.Crouch(true);
            animationcharacter.SetBool("isSitDown", true);
        }
        else if (Input.GetKeyUp(KeyCode.S))
        {
            _pc.Crouch(false);
            animationcharacter.SetBool("isSitDown", false);
        }

        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            if (_pc.attacking)
            {
                return;
            }
            if (_pc.isCrouch)
            {
                return;
            }
            if (_staminabar.fillAmount > _dodgevalue)
            {
                _pc.Dodge(axis);
                _staminabar.fillAmount -= _dodgevalue;
                _pc.CooldownStamina();
                animationcharacter.SetTrigger("Dodge");
            }
            else
            {
                animationcharacter.SetTrigger("Idle");
            }
        }
        if (Input.GetKeyDown(KeyCode.Mouse0) && !_pc.attacking)
        {
            if ((_pc.isCrouch) || (_pc.dodgetrigger) || (!_pc.isGrounded))
            {
                return;
            }

            if (_staminabar.fillAmount > _attackvalue)
            {
                _pc.Attack();
                _staminabar.fillAmount -= _attackvalue;
                _pc.CooldownStamina();
                animationcharacter.SetTrigger("AttackComboOne");
            }
            else
            {
                animationcharacter.SetTrigger("Idle");
            }
        }
        //  if (_pc._wallCheck)
        //   {
        //       _pc.WallStay(axis);
        //   }
    }
예제 #12
0
    void Update()
    {
        if (_enemycontroll.heal < 0)
        {
            animatorenemy.SetTrigger("Dead");
            _enemycontroll.Dead();
        }

        if (_enemycontroll.attacking)
        {
            if (_enemycontroll.attackTimer > 0)
            {
                _enemycontroll.attackTimer -= Time.deltaTime;
            }
            else
            {
                _enemycontroll.attacking             = false;
                _enemycontroll.attackTrigger.enabled = false;
            }
        }


        //  _direction = _target.transform.position.x - transform.position.x;
        if (_Triggergate.isTrigger)
        {
            return;
        }
        if (Vector2.Distance(transform.position, _target.position) > _distans)
        {
            if (!_enemycontroll.isGrounded)
            {
                animatorenemy.SetBool("isFalling", true);
            }
            if (_enemycontroll.isGrounded)
            {
                animatorenemy.SetBool("isJumping", false);
                animatorenemy.SetBool("isFalling", false);
            }
            if (_target.transform.position.x - transform.position.x < 0 && _target.position.y < transform.position.y)
            {
                _enemycontroll.Move(-0.7f);
                animatorenemy.SetBool("isRunning", true);
            }
            else if (_target.transform.position.x - transform.position.x > 0 && _target.position.y < transform.position.y)
            {
                _enemycontroll.Move(0.7f);
                animatorenemy.SetBool("isRunning", true);
            }
            else if (_target.transform.position.x - transform.position.x < 0)
            {
                _enemycontroll.Move(-0.7f);
                animatorenemy.SetBool("isRunning", true);
                if (Mathf.Abs(_target.transform.position.y - transform.position.y) < 3)
                {
                    animatorenemy.SetBool("isRunning", false);
                    animatorenemy.SetBool("isJumping", true);
                    _enemycontroll.Jump();
                }
            }
            else if (_target.transform.position.x - transform.position.x > 0)
            {
                _enemycontroll.Move(0.7f);
                animatorenemy.SetBool("isRunning", true);
                if (Mathf.Abs(_target.transform.position.y - transform.position.y) > 3)
                {
                    animatorenemy.SetBool("isRunning", false);
                    animatorenemy.SetBool("isJumping", true);
                    _enemycontroll.Jump();
                }
            }
            //if (!_pc._isGrounded)
            //  {
            //     animationcharacter.SetBool("isFalling", true);
            // }
            // if (_pc._isGrounded)
            // {
            //      animationcharacter.SetBool("isJumping", false);
            //      animationcharacter.SetBool("isFalling", false);
            //  }

            //transform.position = Vector2.MoveTowards(transform.position, _target.position, _enemycontroll._speed * Time.deltaTime);
            _enemycontroll.Flip();
        }
        else if (!_enemycontroll.attacking)
        {
            _enemycontroll.attackCd = 2f;
            _enemycontroll.Attack();
            animatorenemy.SetTrigger("Attack");
        }


        //_enemycontroll.Move(1f);
        // _enemycontroll.Flip();
    }
    /// <summary>
    /// Update function when state is select and move
    /// </summary>
    private void SelectAndMoveUpdate()
    {
        //SELECT
        //check if left click was pressed
        if (Input.GetButtonDown("Select"))
        {
            //get collider clicked on
            Collider clickedOnCollider = ClickOnCollider();

            //check if player clicked on collider
            if (clickedOnCollider != null)
            {
                //check if clicked on friendly unit AND unit has action
                if (clickedOnCollider.gameObject.CompareTag("Friendly Unit"))
                {
                    //get unitcontroller clicked on
                    UnitController unitController = clickedOnCollider.gameObject.GetComponent <UnitController>();

                    //check if unit has action or not. If it has no action, don't select anything
                    if (!unitController.GetHasAction())
                    {
                        return;
                    }

                    //select unit clicked on
                    SelectUnit(unitController);
                }
                //clicked on ground
                else
                {
                    //unset selected unit
                    DeselectUnit();
                }
            }
        }

        //MOVE
        //check if right click was pressed and there is a selected unit
        else if (Input.GetButtonDown("Alt Select") && _selectedUnit != null)
        {
            //get collider clicked on
            Collider clickedOnCollider = ClickOnCollider();

            //check if player clicked on collider
            if (clickedOnCollider != null)
            {
                Coords oldCoords = _selectedUnit.GetUnitCoords();                                 //the current coords of selected unit
                Coords toCoords  = Grid.WorldSpaceToCoords(clickedOnCollider.transform.position); //the coordinates player clicked on (to move to)

                //check if grid space clicked is selectedunit's own space. Skip movement in that case
                if (grid.GetGridArray(toCoords) == _selectedUnit.gameObject)
                {
                    _selectedUnit.UnhighlightTiles();
                    SetStateAttacking();
                }

                //check and move unit
                else if (_selectedUnit.Move(toCoords))
                {
                    //move was successful, update grid
                    grid.SetGridArray(toCoords, _selectedUnit.gameObject);
                    grid.SetGridArray(oldCoords, null);

                    //state becomes attacking(with selectedunit)
                    SetStateAttacking();
                }
                else
                {
                    //move failed
                    DeselectUnit();
                }
            }
        }
    }
예제 #14
0
 public void setTargetPos(Vector3 target)
 {
     targetPos = target;
     unitController.Move(targetPos);
 }