Skip to content

Commit 0adad49

Browse files
authored
CHANGE: Update project wide sample (#1784)
* Rename ProjectWide Sample * Add namespace to ProjectWide Sample * Add callback example to project wide sample * formatting
1 parent 0a6a542 commit 0adad49

8 files changed

+49
-67
lines changed

Assets/Samples/ProjectWideActionsTest/ProjectWideActionsTest.asmdef renamed to Assets/Samples/ProjectWideActions/ProjectWideActions.asmdef

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "ProjectWideActionsTest",
2+
"name": "ProjectWideActions",
33
"rootNamespace": "",
44
"references": [
55
"GUID:75469ad4d38634e559750d17036d5f7c"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
2+
3+
namespace UnityEngine.InputSystem.Samples.ProjectWideActions
4+
{
5+
public class ProjectWideActionsExample : MonoBehaviour
6+
{
7+
[SerializeField] public GameObject cube;
8+
9+
InputAction move;
10+
InputAction look;
11+
InputAction attack;
12+
InputAction jump;
13+
InputAction interact;
14+
InputAction next;
15+
InputAction previous;
16+
InputAction sprint;
17+
InputAction crouch;
18+
19+
// Start is called before the first frame update
20+
void Start()
21+
{
22+
// Project-Wide Actions
23+
move = InputSystem.actions.FindAction("Player/Move");
24+
look = InputSystem.actions.FindAction("Player/Look");
25+
attack = InputSystem.actions.FindAction("Player/Attack");
26+
jump = InputSystem.actions.FindAction("Player/Jump");
27+
interact = InputSystem.actions.FindAction("Player/Interact");
28+
next = InputSystem.actions.FindAction("Player/Next");
29+
previous = InputSystem.actions.FindAction("Player/Previous");
30+
sprint = InputSystem.actions.FindAction("Player/Sprint");
31+
crouch = InputSystem.actions.FindAction("Player/Crouch");
32+
33+
// Handle input by responding to callbacks
34+
attack.performed += ctx => cube.GetComponent<Renderer>().material.color = Color.red;
35+
attack.canceled += ctx => cube.GetComponent<Renderer>().material.color = Color.green;
36+
}
37+
38+
// Update is called once per frame
39+
void Update()
40+
{
41+
// Handle input by polling each frame
42+
var moveVal = move.ReadValue<Vector2>() * 10.0f * Time.deltaTime;
43+
cube.transform.Translate(new Vector3(moveVal.x, moveVal.y, 0));
44+
}
45+
} // class ProjectWideActionsExample
46+
} // namespace UnityEngine.InputSystem.Samples.ProjectWideActions
47+
48+
#endif

Assets/Samples/ProjectWideActionsTest/ProjectWideActionsTest.cs

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)