// Sets the values of the enemy public void SetInformation(DLLManager.PlayerPacket receivedPacket) { playerID = receivedPacket.id; position = new Vector3(receivedPacket.xPos, receivedPacket.yPos, position.z); cannonAngle = receivedPacket.cannonAngle; firing = receivedPacket.firing; angleZ = receivedPacket.angleZ; }
// Update is called once per frame void Update() { // Check to see if theres a new packet while (PacketCheck()) { // get the size of the struct IntPtr receivedPtr = PacketGet(); // Pops the packet off the queue of them //Marshal.PtrToStructure(receivedPtr, receivedPacket); receivedPacket = (DLLManager.PlayerPacket)Marshal.PtrToStructure(receivedPtr, typeof(DLLManager.PlayerPacket)); //Debug.Log("XPOS: " + receivedPacket.xPos + " YPOS: " + receivedPacket.yPos + " CannonAngle: " + receivedPacket.cannonAngle + " Firing: " + receivedPacket.firing); //Debug.Log("ID Received : " + receivedPacket.id); // ensure that it's not our id if (receivedPacket.id != dllManager.id) { // Check to see if we should update an enemy bool newEnemy = true; foreach (GameObject enemy in enemies) { if (enemy.GetComponent <EnemyVehicle>().playerID == receivedPacket.id) { newEnemy = false; enemy.GetComponent <EnemyVehicle>().SetInformation(receivedPacket); } } // if we have a new enemy to generate if (newEnemy) { GameObject enemy = Instantiate(enemyPref); enemy.GetComponent <EnemyVehicle>().SetInformation(receivedPacket); enemies.Add(enemy); } } //free the pointer Marshal.FreeHGlobal(receivedPtr); } }