예제 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (target == null || !AINavigator.CanReachTargetFrom(turret.muzzle.transform.position, target.gameObject))
        {
            target = FindTarget();
        }

        // Rotate
        if (target != null)
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position, new Vector3(0, 1, 0)), MaxRotation * Time.fixedDeltaTime);
        }
    }
예제 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if ((FindObjectOfType <KillSoldiers> ().transform.position - transform.position).magnitude < killRadius)
        {
            GetComponent <HealthComponent>().Health -= 1;
        }

        animator.SetFloat("Speed", 1);

        if (reloadTimer > 0)
        {
            reloadTimer -= Time.fixedDeltaTime;
        }

        if (target == null || target.IsDead)
        {
            target = FindTarget();
        }
        else
        {
            if (!AINavigator.CanReachTargetFrom(navigator.navTarget.position, target.gameObject))
            {
                Vector2 sphere  = Random.insideUnitCircle;
                Vector3 sphere2 = new Vector3(sphere.x, 0, sphere.y);
                navigator.navTarget.position = target.transform.position + sphere2 * distance;
            }
        }



        // Calculate turret's target
        var turretTarget = turret.GetVisualTarget();

        if (turretTarget)
        {
            var h = turretTarget.GetComponent <HealthComponent> ();
            if (h == null)
            {
                h = turretTarget.GetComponentInParent <HealthComponent> ();
            }

            if (h && h.Team == EnemyTeam)
            {
                if (reloadTimer <= 0)
                {
                    turret.Fire();
                    reloadTimer = ReloadTime;
                }
            }
        }
    }
예제 #3
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.GetComponentInParent <NpcType>() != _spawningNpc)
        {
            _dockingNpcNav = other.gameObject.GetComponentInParent <AINavigator>();
            if (_dockingNpcNav != null)
            {
                _dockingNpcNav.Dock(type);
            }
        }

        //if (_dockingNpcNav != null && _dockingNpcNav.Destination == this.gameObject)
        //{
        //    _dockingNpcNav.DestinationReached += OtherNav_DestinationReached;
        //}
    }
예제 #4
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.GetComponentInParent<NpcType>() != _spawningNpc)
        {
            _dockingNpcNav = other.gameObject.GetComponentInParent<AINavigator>();
            if (_dockingNpcNav != null)
            {
                _dockingNpcNav.Dock(type);
            }
        }

        //if (_dockingNpcNav != null && _dockingNpcNav.Destination == this.gameObject)
        //{
        //    _dockingNpcNav.DestinationReached += OtherNav_DestinationReached;
        //}
    }
예제 #5
0
    public HealthComponent FindTarget()
    {
        float           n  = float.PositiveInfinity;
        HealthComponent bh = null;

        foreach (var h in FindObjectsOfType <HealthComponent>())
        {
            if (h.Team == EnemyTeam && AINavigator.CanReachTargetFrom(turret.muzzle.transform.position, h.gameObject))
            {
                float d = (h.transform.position - transform.position).magnitude;
                if (d < n)
                {
                    bh = h;
                    n  = d;
                }
            }
        }
        return(bh);
    }
예제 #6
0
    public void SpawnNpc(GameObject randomPrefab, List <NpcAccessPoint> compatibleDestinations)
    {
        if (randomPrefab == null)
        {
            throw new System.ArgumentNullException("randomPrefab");
        }
        if (compatibleDestinations == null || compatibleDestinations.Count <= 0)
        {
            throw new System.ArgumentNullException("compatibleDestinations");
        }

        Debug.Log(string.Format("Spawned an NPC at: {0}", Time.time));
        GameObject npc = Instantiate(randomPrefab, transform.position, transform.rotation) as GameObject;

        _spawningNpc = npc.GetComponent <NpcType>();
        if (_spawningNpc != null)
        {
            _spawningNpc.Spawn(this);
        }
        else
        {
            Debug.LogError("An NPC is missing its NpcType component");
        }

        AINavigator npcNav = npc.GetComponent <AINavigator>();

        if (npcNav != null)
        {
            GameObject destination = compatibleDestinations[Random.Range(0, compatibleDestinations.Count - 1)].gameObject;
            npcNav.Start(destination);
        }
        else
        {
            Debug.LogError("An NPC is missing its AINavigator component");
        }
    }
예제 #7
0
 private void SpawnNPC(NPCSpawnPoint destination)
 {
     GameObject  ship    = Instantiate(shipPrefabs[Random.Range(0, shipPrefabs.Length - 1)], transform.position, transform.rotation) as GameObject;
     AINavigator shipNav = ship.GetComponent <AINavigator>();
 }
예제 #8
0
 void Start()
 {
     navigator = GetComponent <AINavigator> ();
     animator  = GetComponent <Animator> ();
 }
예제 #9
0
 void Initialize()
 {
     navigator = this.GetComponent <AINavigator>();
     parking   = this.GetComponent <AIParking>();
     takeoff   = this.GetComponent <AITakeoff>();
 }
예제 #10
0
 void Start()
 {
     navigator         = GetComponentInParent <AINavigator>();
     controller        = GetComponentInParent <HovercarAdvanced>();
     detectedBuildings = new List <Transform>();
 }