[Player][MainLevel] Add Player prefab. Configure touch input. Configure RigidBody physics and colliders. Add placeholder main map with placeholder tiles and sprites

This commit is contained in:
Michal Pikulski
2025-09-01 13:14:21 +02:00
parent f8d80aac62
commit 90782f0fb0
77 changed files with 25860 additions and 13 deletions

View File

@@ -1,4 +1,7 @@
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
// Basic touch/mouse movement controller suitable for top-down 2D or 3D overworld
// Attach to the player GameObject. Works with or without Rigidbody/Rigidbody2D.
@@ -40,23 +43,35 @@ public class PlayerTouchController : MonoBehaviour
void HandleInput()
{
#if ENABLE_INPUT_SYSTEM
// Using the new Unity Input System (InputSystem package) only.
// Touch input (mobile)
if (Input.touchCount > 0)
if (Touchscreen.current != null && Touchscreen.current.touches.Count > 0)
{
Touch t = Input.GetTouch(0);
if (t.phase == TouchPhase.Began || t.phase == TouchPhase.Moved || t.phase == TouchPhase.Stationary)
var touch = Touchscreen.current.touches[0];
// press indicates the touch is down; use position even while moved/held
if (touch.press != null && touch.press.isPressed)
{
SetTargetFromScreenPoint(t.position);
Vector2 pos = touch.position.ReadValue();
SetTargetFromScreenPoint(new Vector3(pos.x, pos.y, 0f));
return;
}
}
else
// Mouse support (Editor/PC)
if (Mouse.current != null && Mouse.current.leftButton != null && Mouse.current.leftButton.isPressed)
{
// Mouse input for editor/testing
if (Input.GetMouseButton(0))
{
SetTargetFromScreenPoint(Input.mousePosition);
}
Vector2 mpos = Mouse.current.position.ReadValue();
SetTargetFromScreenPoint(new Vector3(mpos.x, mpos.y, 0f));
}
#else
// Input System package not yet enabled/installed. Provide a helpful runtime message.
// This branch ensures the script compiles until the package is installed and Player Settings are set.
if (Application.isPlaying)
{
Debug.LogError("PlayerTouchController: New Input System is not enabled. Install 'com.unity.inputsystem' and set Active Input Handling to 'Input System Package' (or Both) in Player Settings, then restart the Editor.");
}
#endif
}
void SetTargetFromScreenPoint(Vector3 screenPoint)
@@ -120,4 +135,3 @@ public class PlayerTouchController : MonoBehaviour
}
}
}