Пример #1
0
 // Use this for initialization
 void Start()
 {
     eu   = transform.parent.GetComponent <EnemyUpdate>();
     eh   = transform.parent.GetComponent <EnemyHealth>();
     ea   = transform.parent.GetComponent <EnemyAttack>();
     anim = GetComponent <Animator>();
 }
Пример #2
0
 // Use this for initialization
 void Start()
 {
     eu = GetComponent <EnemyUpdate>();
     ch = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterHealth>();
 }
Пример #3
0
    void SpawnEnemy(GameObject prefab)
    {
        EnemyBehaviour enemyBehaviour = Instantiate(prefab, spawnPoint).GetComponent <EnemyBehaviour>();

        UpdateEvent += enemyBehaviour.EnemyCallback;
    }
    // Use this for initialization
    void Start()
    {
        try
        {
            intervals        = 0;
            battleEnded      = false;
            endGameDisplayed = false;
            //remote endpoint of the server
            IPEndPoint remoteEP = new IPEndPoint(IP, BATTLE_PORT);

            //create TCP socket
            client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            //connect to remote endpoint
            client.Connect(remoteEP);

            //initializations
            isClient = new byte[1];
            spawn    = new byte[1];
            update   = new byte[UPDATE_SIZE];

            UnityEngine.Debug.Log("Connect Successful");

            player     = GameObject.FindGameObjectWithTag("Player");
            opponent   = GameObject.FindGameObjectWithTag("Enemy");
            controller = player.GetComponent <PlayerControl>();
            pstatus    = player.GetComponent <PlayerStatus>();
            estatus    = opponent.GetComponent <PlayerStatus>();

            updateTime.Start();

            receiveUpdate = false;
            sendUpdate    = false;

            readUpdate = new ManualResetEvent(false);
            updateFin  = new ManualResetEvent(true);

            eUpdate = new EnemyUpdate();

            //send the players id to the server
            client.Send(Player.playerID.ToByteArray());

            //send the battle guid to the client in order to connect to opponent
            client.Send(BattleID.ToByteArray());

            byte[] opponentLevel = new byte[1];
            client.Receive(opponentLevel, 1, 0);
            EnemyStatus.setLevel(opponentLevel[0]);

            //gets which spawn to use
            if (client.Receive(spawn, 1, 0) == 0)
            {
                //if socket closed by server throw exception to return to overworld
                throw new Exception("Connection timed out");
            }
            //get player spawn info from index of player given by server
            player.transform.position = spawns[spawn[0]].SpawnPos;
            player.transform.rotation = spawns[spawn[0]].SpawnRot;
            //spawn opponent at the other location
            opponent.transform.position = spawns[(spawn[0] + 1) % 2].SpawnPos;
            opponent.transform.rotation = spawns[(spawn[0] + 1) % 2].SpawnRot;

            //Debug.Log("Send GUID Successful");

            //initial update
            client.Send(getUpdate());

            //Debug.Log("Send Update Successful");

            //start receiving updates from server
            client.BeginReceive(isClient, 0, 1, 0, new AsyncCallback(updateDriver), null);
            //Debug.Log("Start async successful");
        }
        //catch exception if fail to connect
        catch (Exception e)
        {
            UnityEngine.Debug.Log(e.Message);

            //display message to user failed to connect to battle

            //send back to overworld
            //SceneManager.LoadScene("Overworld");
            LoadingScreen.GetComponent <SceneLoader>().LoadScene("Overworld");
        }
    }