Exemplo n.º 1
0
    //recebe do servidor uma shootsheep message
    private void OnReceiveShootSheepMessage(NetworkMessage _message)
    {
        ShootSheepMessage _msg = _message.ReadMessage <ShootSheepMessage>();

        if (_msg.playerName != transform.name)
        {
            sheepManager.GetComponent <SheepAI>().processShootSheepMessage(_msg);
        }
    }
Exemplo n.º 2
0
    public void SendShootSheep(NetworkMessage _message)
    {
        ShootSheepMessage _msg = _message.ReadMessage <ShootSheepMessage>();

        GameObject sheepManager = GameObject.Find("SheepManager");
        GameObject sheep        = sheepManager.transform.Find(_msg.sheepName).gameObject;
        Rigidbody  sheep_rb     = sheep.GetComponent <Rigidbody>();

        sheep_rb.AddRelativeForce(new Vector3(0, 0.1f, -1.2f) * _msg.impulse, ForceMode.Impulse);

        NetworkServer.SendToAll(shoot_sheep_message, _msg);
    }
    public void SendShootSheepMessage(string _sheepID, int state, int anim_index, float impulse)
    {
        ShootSheepMessage _msg = new ShootSheepMessage()
        {
            playerName     = transform.name,
            sheepName      = _sheepID,
            sheepState     = state,
            sheepAnimation = anim_index,
            impulse        = impulse
        };

        NetworkManager.singleton.client.Send(shoot_sheep_message, _msg);
    }
    public void processShootSheepMessage(ShootSheepMessage _msg)
    {
        GameObject sheep = GameObject.Find(_msg.sheepName);

        if (sheep != null)
        {
            SheepMovement sheep_movement = sheep.GetComponent <SheepMovement>();
            Animator      sheep_animator = sheep.GetComponentInChildren <Animator>();
            Rigidbody     sheep_rb       = sheep.GetComponent <Rigidbody>();

            // set state to flying and anim state to shot
            sheep_movement.setFlying();
            IAnimState animState = new Shot(ref sheep_animator);
            sheep_movement.SetAnimState(animState);

            sheep_rb.velocity   = Vector3.zero;
            sheep_rb.useGravity = true;

            // ignoreCollisionWithBases(sheep, false);
            ignoreCollisionWithPlayers(sheep, false);
            sheep_movement.setPickedUpBy("");
        }
    }