Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (unitState != e_unitStates.moving && enemiesInRange.Count > 0)
        {
            if (enemiesInRange[0] != null)
            {
                print("attacking: " + enemiesInRange[0].name);
                timer -= Time.deltaTime;
                if (timer <= 0.0f)
                {
                    Attack(enemiesInRange[0].GetComponent <AgentMovement>());
                }
                //attack(enemiesInRange[0]);
            }
            else
            {
                enemiesInRange.RemoveAt(0);
            }
        }
        else if (agent.remainingDistance > destinationThreshold && (unitState == e_unitStates.moving || enemiesInRange.Count == 0))
        {
            agent.Resume();
        }

        if (unitState != e_unitStates.stationary && agent.remainingDistance <= destinationThreshold)
        {
            if (agent.remainingDistance == 0)
            {
                agent.Stop();
                unitState = e_unitStates.stationary;
            }
            else if (targetOccupied)
            {
                agent.Stop();
                unitState = e_unitStates.stationary;
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            if (Input.GetKey(KeyCode.LeftControl))
            {
                RaycastHit hit;

                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
                {
                    moveCommand(hit.point, null, true);
                }
            }
            else
            {
                RaycastHit hit;

                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
                {
                    moveCommand(hit.point);
                }
            }
        }
    }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     agent          = GetComponent <NavMeshAgent>();
     unitState      = e_unitStates.stationary;
     enemiesInRange = new List <GameObject>();
     agent.speed    = speed;
 }
Ejemplo n.º 3
0
    void moveCommand(Vector3 targetPos, GameObject targetEnemy = null, bool attackMove = false)
    {
        target.position = targetPos;
        enemyTarget     = targetEnemy;
        //set this unit's state
        if (!attackMove)
        {
            unitState = e_unitStates.moving;
        }
        else
        {
            unitState = e_unitStates.attackmoving;
        }

        agent.SetDestination(targetPos);
    }