예제 #1
0
    public void stopMoving()
    {
        if (tag == "Enemy")
        {
            if (Vector3.Distance(transform.position, TargetPos) < 10)
            {
                newPosition(TargetPos);
                return;
            }
        }

        if (state == AllyState.BUILDING)
        {
            NewCover();
            return;
        }

        if (movingToCover)
        {
            allyAI.stoppingDistance = 3;
            movingToCover           = false;
            state = AllyState.COVER;
            anim.SetTrigger("CombatIdle");
        }

        else
        {
            state = AllyState.STOPPED;
        }

        newPosition(this.gameObject.transform.position);
    }
예제 #2
0
    public void NewCover()
    {
        Vector3    relativePos = allyAI.destination - TargetPos;
        Quaternion rot         = Quaternion.LookRotation(relativePos);

        rot.z = 0;
        rot.x = 0;

        GameObject obj = Instantiate(coverPrefab, allyAI.destination, Quaternion.identity);

        obj.transform.rotation = rot;

        state = AllyState.STOPPED;

        newPosition(this.gameObject.transform.position);
    }
예제 #3
0
    public void NoEnemy()
    {
        anim.SetBool("CombatShoot", false);

        CancelInvoke();

        if (state == AllyState.COVERSHOOTING)
        {
            state = AllyState.COVER;
        }

        else
        {
            state = AllyState.STOPPED;
        }
    }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        state = AllyState.STOPPED;

        anim = GetComponent <Animator>();

        player = GameObject.FindGameObjectWithTag("Player");

        TargetPos = GameObject.FindGameObjectWithTag("Target").transform.position;

        if (tag == "Ally")
        {
            accuracy /= 2.5f;

            foreach (GameObject ally in GameObject.FindGameObjectsWithTag("Ally"))
            {
                if (ally != this.gameObject)
                {
                    allies.Add(ally);
                }
            }
        }

        else if (tag == "Enemy")
        {
            foreach (GameObject ally in GameObject.FindGameObjectsWithTag("Enemy"))
            {
                if (ally != this.gameObject)
                {
                    allies.Add(ally);
                }
            }
        }

        allyAI = GetComponent <UnityEngine.AI.NavMeshAgent> ();

        stopMoving();

        if (tag == "Enemy")
        {
            newPosition(TargetPos);
        }
    }
예제 #5
0
    public void NewEnemy()
    {
        if (!movingToCover)
        {
            if (state == AllyState.COVER)
            {
                state = AllyState.COVERSHOOTING;
            }

            else
            {
                state = AllyState.SHOOTING;
            }

            anim.SetBool("CombatShoot", true);

            InvokeRepeating("GunFlash", 1, 1);
        }
    }
예제 #6
0
    public void MoveToCover(GameObject newCover)
    {
        GameObject closest = null;

        state = AllyState.MOVING;

        int spots = 3;

        foreach (Transform child in newCover.transform)
        {
            if (child.tag == "CoverPoint")
            {
                if (child.GetComponent <CoverPoint>().Occupied == true)
                {
                    spots--;
                }
            }
        }

        if (spots > 0)
        {
            closest = newCover;
        }


        if (closest != null)
        {
            foreach (Transform child in closest.transform)
            {
                if (child.tag == "CoverPoint")
                {
                    if (child.GetComponent <CoverPoint>().Occupied == false)
                    {
                        allyAI.stoppingDistance = 0.1f;
                        child.GetComponent <CoverPoint>().Occupied = true;
                        newPosition(child.transform.position);
                        movingToCover = true;
                        return;
                    }
                }
            }
        }
    }
예제 #7
0
    public void FindCover()
    {
        state = AllyState.MOVING;

        GameObject[] covers;
        covers = GameObject.FindGameObjectsWithTag("Cover");

        GameObject closest    = null;
        float      closestDis = 1000.0f;;

        foreach (GameObject cover in covers)
        {
            float dis = Vector3.Distance(transform.position, cover.transform.position);

            if (dis < closestDis)
            {
                int spots = 3;
                foreach (Transform child in cover.transform)
                {
                    if (child.tag == "CoverPoint")
                    {
                        if (child.GetComponent <CoverPoint>().Occupied == true)
                        {
                            spots--;
                        }
                    }
                }

                if (spots > 0)
                {
                    closestDis = dis;
                    closest    = cover;
                }
            }
        }

        if (closest != null)
        {
            movingToCover = true;

            MoveToCover(closest);
        }
    }