Пример #1
0
    public Vector3 GetTarget()
    {
        string targetType = stats.GetTargetType();

        if (targetType == "Wander")
        {
            Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * 5;
            randomDirection += transform.position;
            NavMeshHit hit;
            NavMesh.SamplePosition(randomDirection, out hit, 25, 1);
            return(hit.position);
        }

        if (targetWater != null && Vector3.Distance(targetWater.transform.position, this.transform.position) < 3.0f && targetType == "Thirsty")
        {
            stats.Drink();
            targetWater = null;
            return(transform.position);
        }

        if (targetPlant != null && Vector3.Distance(targetPlant.transform.position, this.transform.position) < 4.0f)
        {
            stats.Eat();
            DestroyObject(targetPlant.gameObject);

            targetPlant = null;
            Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * 5;
            randomDirection += transform.position;
            NavMeshHit hit;
            NavMesh.SamplePosition(randomDirection, out hit, 25, 1);

            Instantiate(plantPrefab, hit.position, Quaternion.identity);
            return(transform.position);
        }



        if (targetType == "Hungry")
        {
            if (targetPlant != null)
            {
                return(targetPlant.transform.position);
            }
            else if (targetWater != null && stats.IsThirsty())
            {
                return(targetWater.transform.position);
            }
            else
            {
                Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * 5;
                randomDirection += transform.position;
                NavMeshHit hit;
                NavMesh.SamplePosition(randomDirection, out hit, 25, 1);
                return(hit.position);
            }
        }
        else if (targetType == "Thirsty")
        {
            if (targetWater != null)
            {
                return(targetWater.transform.position);
            }
            else if (targetPlant != null)
            {
                return(targetPlant.transform.position);
            }
            else
            {
                Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * 5;
                randomDirection += transform.position;
                NavMeshHit hit;
                NavMesh.SamplePosition(randomDirection, out hit, 25, 1);
                return(hit.position);
            }
        }
        else
        {
            Vector3 randomDirection = UnityEngine.Random.insideUnitSphere * 5;
            randomDirection += transform.position;
            NavMeshHit hit;
            NavMesh.SamplePosition(randomDirection, out hit, 25, 1);
            return(hit.position);
        }
    }