Esempio n. 1
0
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnStateEnter(animator, stateInfo, layerIndex);
        TimeTickSystem.OnTick += TimeTickSystem_OnTick;

        targetResource = aIController.actualTarget.GetComponent <Resource>();

        Vector2 direction = BigBookBasic.GetDirectionVector2(targetResource.transform.position, unitObject.transform.position);

        characterAnimator.GetAnimationFromVector2(direction.x, direction.y, targetResource.killAnimation);
    }
Esempio n. 2
0
    IEnumerator FollowPath()
    {
        bool followingPath = true;
        int  pathIndex     = 0;
        //normalized richting bepalen ivm niet kunnen draaien in 2D
        Vector2 direction   = (path.lookPoints[0] - transform.position).normalized;
        Vector2 destination = path.lookPoints[0];

        ac.AnimateDirection(direction, CharacterAnimationState.Walk);

        float speedPercent = 1f;

        while (followingPath)
        {
            if (followingPath)
            {
                if (Vector2.Distance(new Vector2(transform.position.x, transform.position.y), destination) < stoppingDistance)
                {
                    if (destination == new Vector2(ac.targetPosition.position.x, ac.targetPosition.position.y))
                    {
                        followingPath = false;
                        ac.animator.SetBool("HasArrived", true);
                        ac.AnimateSpecific(CharacterAnimationState.Idle);
                        yield return(null);
                    }

                    pathIndex++;
                    if (pathIndex >= path.lookPoints.Length)
                    {
                        destination = ac.targetPosition.position;
                    }
                    else
                    {
                        destination = path.lookPoints[pathIndex];
                    }

                    direction = BigBookBasic.GetDirectionVector2(destination, transform.position);
                    ac.AnimateDirection(direction, CharacterAnimationState.Walk);
                }
                transform.Translate(direction * Time.deltaTime * speed * speedPercent);
            }
            yield return(null);
        }
        ac.AnimateSpecific(CharacterAnimationState.Idle);
        ac.animator.SetBool("HasArrived", true);
    }
Esempio n. 3
0
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnStateEnter(animator, stateInfo, layerIndex);
        TimeTickSystem.OnTick += TimeTickSystem_OnTick;

        gather   = unit.gather;
        resource = aIController.actualTarget.GetComponent <Resource>();
        if (resource)
        {
            Vector2 direction = BigBookBasic.GetDirectionVector2(resource.transform.position, unitObject.transform.position);
            characterAnimator.GetAnimationFromVector2(direction.x, direction.y, resource.gatherAnimation);
        }
        else
        {
            animator.SetBool("HasArrived", true);
            animator.SetBool("IsGathering", false);
        }
    }