예제 #1
0
    // Update is called once per frame
    void Update()
    {
        timeSinceLastGather += Time.deltaTime;
        if (ShouldMove())
        {
            RaycastHit hit;
            Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                model.GetComponent <AnimatorController> ().RotateModel(model, hit.transform.gameObject, 150); //rotate to face towards pointer

                if (objectsInMeleeRange.Contains(hit.transform.gameObject))                                   // if close enough to object, attempt to gather
                {
                    if (timeSinceLastGather >= 0.5f)                                                          // this check allows to gather once every second
                    {
                        resourceController.Gather(model, hit, skillsController);
                        timeSinceLastGather = 0;
                    }
                }
                else                     // else walk to object
                {
                    Walk(hit);
                }
            }
        }
        else
        {
            model.GetComponent <Animator> ().SetBool("walking", false);             // else do nothing
        }
        if (Input.GetKeyUp(KeyCode.K))
        {
            skillsHUD.SetActive(!skillsHUD.activeInHierarchy);
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        timeSinceLastGather += Time.deltaTime;
        if (ShouldMove())
        {
            RaycastHit hit;
            Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                model.GetComponent <AnimatorController> ().RotateModel(model, hit.transform.gameObject, 150); //rotate to face towards pointer

                if (objectsInMeleeRange.Contains(hit.transform.gameObject))                                   // if close enough to object, attempt to gather
                {
                    if (timeSinceLastGather >= 0.5f)                                                          // this check allows to gather once every second
                    {
                        resourceController.Gather(model, hit, skillsController);
                        timeSinceLastGather = 0;
                    }
                }
                else                     // else walk to object
                {
                    Walk(hit);
                }
            }
        }
        else
        {
            model.GetComponent <Animator> ().SetBool("walking", false);             // else do nothing
        }
        if (Input.GetKeyUp(KeyCode.K))
        {
            skillsHUD.SetActive(!skillsHUD.activeInHierarchy);
        }

        underFootTile = Utils.GetTileFromTransformPosition(transform.position);
        if (target != null && underFootTile != null)
        {
            distanceToTarget = Utils.GetASharpDistance(underFootTile.transform.position, target.position);
            Vector3 targetPosition = target.transform.position;
            target     = null;
            aSharpPath = Utils.GetASharpPath(targetPosition, transform.position, pathMaterial);
        }
    }