Beispiel #1
0
    public override void Update()
    {
        base.Update();

        if (execute)
        {
            if (GetComponent <Root>().HP > 0)
            {
                lastpos = transform.position;
            }
            playerobjs = GameObject.FindGameObjectsWithTag("Player");


            find_closest_player(); //from parent
            melee_attack_player(); //from parent
        }
        else
        {
            GetComponent <Rigidbody>().AddForce(new Vector3(0, -50, 0));
        }

        if (toHandle != null)
        {
            agent.enabled      = false;
            transform.position = toHandle.Position;
            agent.enabled      = true;
            agent.nextPosition = toHandle.Position;

            if (currplayerobj.GetComponent <PlayerControl>().ID != toHandle.TargetID)
            {
                var temp = GameObject.FindObjectsOfType <PlayerControl>();

                foreach (var player in temp)
                {
                    if (player.ID == toHandle.TargetID)
                    {
                        agent.SetDestination(player.transform.position);

                        currplayerobj     = player.gameObject;
                        currplayerobjroot = player.GetComponent <Root>();
                    }
                }
            }

            toHandle      = null;
            lastUpdate    = DateTime.Now;
            hasSentPacket = false;
        }

        if (Network.IsHost && (DateTime.Now - lastSync).TotalMilliseconds > Network.UpdateInterval)
        {
            AIMeleeBasicPack pack = new AIMeleeBasicPack(transform.position, currplayerobj.GetComponent <PlayerControl>().ID, networkID);
            Network.Send(pack);

            lastSync      = DateTime.Now;
            hasSentPacket = false;
        }
    }
Beispiel #2
0
    void OnReceive(NetworkPacket packet, string id)
    {
        if (packet.Header == PacketType.AIMeleeBasicPack)
        {
            AIMeleeBasicPack pack = (AIMeleeBasicPack)packet;

            if (pack.AIID == this.networkID)
            {
                toHandle = pack;

                wave_control.Instance.toReactivate.Enqueue(gameObject);
            }
        }
    }