Exemplo n.º 1
0
    IEnumerator RotateTo(GameObject target, Vector3 point)
    {
        for (int i = 0; i < 20; i++)
        {
            GameObject.FindGameObjectWithTag("PlayerModel").GetComponent <Animator>().speed = 3;
            var targetRotation = Quaternion.LookRotation(target.transform.position - transform.position);

            // Smoothly rotate towards the target point.
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 5 * Time.deltaTime);
            yield return(new WaitForEndOfFrame());
        }


        if (target.GetComponent <Gatherable>() != null)
        {
            GetComponent <CharacterGatherController>().GatherResource();

            if (target.GetComponent <Gatherable>() != null)
            {
                Gatherable gatherObject = target.GetComponent <Gatherable>();

                if (gatherObject != null)
                {
                    // Gatherable object found and clicked on! Do shit.
                    if (gatherObject.resourceType == PublicEnums.ItemType.Stone)
                    {
                        Instantiate(GetComponent <CharacterGatherController>().StoneParticleSystem, point, Quaternion.identity);
                    }
                    else if (gatherObject.resourceType == PublicEnums.ItemType.Wood)
                    {
                        Instantiate(GetComponent <CharacterGatherController>().WoodParticleSystem, point, Quaternion.identity);
                    }
                    if (gatherObject.GetComponent <AudioSource>() != null)
                    {
                        gatherObject.GetComponent <AudioSource>().Play();
                    }
                }
            }

            target.GetComponent <Gatherable>().Gather(gameObject);
        }
        else if (target.GetComponent <Combatable>() != null)
        {
            RaycastHit hit;
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit);
            _combat.Attack(target.transform.gameObject);
            Instantiate(GetComponent <Combatable>().BloodParticles, point, Quaternion.identity);
            if (target.GetComponent <AudioSource>() != null)
            {
                target.GetComponent <AudioSource>().Play();
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        GetComponent <Animator>().speed = _navMeshAgent.velocity.magnitude / 3;


        List <GameObject> VisibleLights;
        GameObject        player;

        if ((player = FindPlayer()) != null)
        {
            if ((player.transform.position - transform.position).magnitude > _stats.range - 0.5f)
            {
                _navMeshAgent.SetDestination(player.transform.position);
            }
            else
            {
                _navMeshAgent.SetDestination(transform.position);
                _combat.Attack(player);
            }
        }
        else if ((VisibleLights = FindLights()).Any())
        {
            if ((FindClosestLight(VisibleLights).transform.position - transform.position).magnitude > 0.5f)
            {
                _navMeshAgent.SetDestination(FindClosestLight(VisibleLights).transform.position);
            }
            else
            {
                _navMeshAgent.SetDestination(transform.position);
            }
        }



        else if (_wanderPosition == Vector3.zero || (transform.position - _wanderPosition).magnitude < 2)
        {
            _wanderPosition = RandomNavSphere(transform.position, seeDistance, 0);
            _navMeshAgent.SetDestination(_wanderPosition);
        }
    }