Weapon Pickup

版本检查: 2018.1

-

难度: 新手

By default in the 3D Gamekit, Ellen has her weapon activated and can attack the monsters. For this example, we will look at disabling her ability to attack and activate it again on pickup from the pedestal similar to how the game demo levels work.

  • To disable Ellen’s attacking ability, select Ellen and in the Inspector locate the Player Controller component.

  • Disable the Can Attack setting

Find the Weapon Pedestal Prefab in 3DGamekit > Prefabs > Interactables and drag it into the scene to add it.

  • In the Hierarchy view, expand the group of WeaponPedestal to show the other GameObjects in the prefab.

The three GameObjects are:

  • StaffTakeTrigger

  • WeaponPedestal

  • Staff

  • Select the StaffTakeTrigger GameObject in Hierarchy view.

In the Inspector you can see that it has a Sphere Collider component and an Interact On Trigger script component with a few predefined values on the properties of the script. This is to save setup time on the pedestal and allow you to have ready made logic without the need for code.

To allow the Pedestal to update Ellen’s ability to attack we need to attach the Ellen GameObject from the Hierarchy.

  • Drag Ellen from the Hierarchy view into the top property field. When it accepts the GameObject, select a function from the drop down titled PlayerController.SetCanAttack this will default to True (enabled).

  • Play your scene and Ellen should not be able to attack when you spawn in, walk over to the pedestal and the collider should activate Ellen’s ability to attack and make the staff disappear.