-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputManager.cs
More file actions
49 lines (43 loc) · 1.4 KB
/
InputManager.cs
File metadata and controls
49 lines (43 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using UnityEngine;
using UnityEngine.InputSystem; // Import the new Input System namespace
public class InputManager : MonoBehaviour
{
public float pushForce = 100f;
private Camera mainCamera;
void Start()
{
mainCamera = Camera.main;
}
void Update()
{
// Check for mouse presence and left button click using the new Input System
if (Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame)
{
HandleMouseClick();
}
}
void HandleMouseClick()
{
// Use the new Input System to get the mouse position
Ray ray = mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue());
if (Physics.Raycast(ray, out RaycastHit hit))
{
// Check if the clicked object is a domino
if (hit.collider.CompareTag("Domino"))
{
PushDomino(hit.collider.gameObject, hit.point);
}
}
}
void PushDomino(GameObject domino, Vector3 hitPoint)
{
Rigidbody rb = domino.GetComponent<Rigidbody>();
if (rb != null)
{
// By default, push the domino along its forward (thin) direction
// This creates a consistent chain reaction along the path
Vector3 pushDirection = domino.transform.forward;
rb.AddForce(pushDirection * pushForce, ForceMode.Impulse);
}
}
}