Exemplo n.º 1
0
        private void OnTriggerStay(Collider other)
        {
            if (isServer)
            {
                return;
            }

            if (other.tag == "Player")
            {
                var player_identity = other.GetComponentInParent <NetworkIdentity>();
                if (player_identity.isLocalPlayer && !isBeingHeld)
                {
                    ItemCanvas.SetActive(true);
                    var player_behaviour = player_identity.GetComponent <PlayerBehaviour>();
                    //var camTransform = player_behaviour.VirtualCamera.GetComponent<Cinemachine.CinemachineFreeLook>().GetRig(1).transform;
                    var cinemachine_rig = player_behaviour.VirtualCamera.GetComponent <Cinemachine.CinemachineFreeLook>().LiveChildOrSelf;
                    var camTransform    = cinemachine_rig.VirtualCameraGameObject.transform;
                    ItemUILookat(camTransform);
                }

                var player_interaction = other.GetComponentInParent <PlayerInteractionBehaviour>();
                if (player_interaction != null)
                {
                    player = player_interaction;
                }
            }

            if (other.CompareTag("Hand"))
            {
                var player_interaction = other.GetComponentInParent <PlayerInteractionBehaviour>();
                if (player_interaction != null)
                {
                    if (!player_interaction.isHolding && !isBeingHeld)
                    {
                        PickUp(player_interaction);
                    }
                }
            }

            if (other.tag == "Vehicle")
            {
                Debug.Log("COLLISION WITH: " + other.gameObject.name);

                var vehicle_behaviour = other.GetComponentInParent <VehicleBehaviour>();
                var vehicle_identity  = other.GetComponentInParent <NetworkIdentity>();

                if (isBeingHeld && player.isLocalPlayer && !vehicle_behaviour.isDestroyed)
                {
                    var string_type = _I.GetType().ToString();          //GET THE TYPE OF ITEM
                    player.CmdAssignVehicleAuthority(vehicle_identity); //ASSIGN THE VEHICLE 'AUTHORITY'

                    if (vehicle_identity.hasAuthority)
                    {
                        player.UseItemOnVehicle(string_type, item_network_identity, vehicle_identity); //USE THE ITEM ON THE VEHICLE
                        player.playerBrain.CmdRemoveVehicleAuthority(vehicle_identity);                //REMOVE THE AUTHORITY FROM THE VEHICLE
                        player._DropItem();                                                            //REMOVE THE ITEM FROM THE PLAYER

                        var net_companion = FindObjectOfType <InGameNetworkBehaviour>();
                        net_companion.Server_Destroy(gameObject);
                    }
                }
            }
        }