1
0

initial commit

This commit is contained in:
LupiNexMedia
2026-04-28 09:32:03 +02:00
commit f84f5c592b
2173 changed files with 376140 additions and 0 deletions
@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collectible2D : MonoBehaviour
{
public float rotationSpeed = 0.5f;
public GameObject onCollectEffect;
// Update is called once per frame
void Update()
{
transform.Rotate(0, 0, rotationSpeed);
}
private void OnTriggerEnter2D(Collider2D other) {
// Check if the other object has a PlayerController2D component
if (other.GetComponent<PlayerController2D>() != null) {
// Destroy the collectible
Destroy(gameObject);
// Instantiate the particle effect
Instantiate(onCollectEffect, transform.position, transform.rotation);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 613c788f1945544f5baa134130a6b70d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,78 @@
using UnityEngine;
public class PlayerController2D : MonoBehaviour
{
// Public variables
public float speed = 5f; // The speed at which the player moves
public bool canMoveDiagonally = true; // Controls whether the player can move diagonally
// Private variables
private Rigidbody2D rb; // Reference to the Rigidbody2D component attached to the player
private Vector2 movement; // Stores the direction of player movement
private bool isMovingHorizontally = true; // Flag to track if the player is moving horizontally
void Start()
{
// Initialize the Rigidbody2D component
rb = GetComponent<Rigidbody2D>();
// Prevent the player from rotating
rb.constraints = RigidbodyConstraints2D.FreezeRotation;
}
void Update()
{
// Get player input from keyboard or controller
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
// Check if diagonal movement is allowed
if (canMoveDiagonally)
{
// Set movement direction based on input
movement = new Vector2(horizontalInput, verticalInput);
// Optionally rotate the player based on movement direction
RotatePlayer(horizontalInput, verticalInput);
}
else
{
// Determine the priority of movement based on input
if (horizontalInput != 0)
{
isMovingHorizontally = true;
}
else if (verticalInput != 0)
{
isMovingHorizontally = false;
}
// Set movement direction and optionally rotate the player
if (isMovingHorizontally)
{
movement = new Vector2(horizontalInput, 0);
RotatePlayer(horizontalInput, 0);
}
else
{
movement = new Vector2(0, verticalInput);
RotatePlayer(0, verticalInput);
}
}
}
void FixedUpdate()
{
// Apply movement to the player in FixedUpdate for physics consistency
rb.linearVelocity = movement * speed;
}
void RotatePlayer(float x, float y)
{
// If there is no input, do not rotate the player
if (x == 0 && y == 0) return;
// Calculate the rotation angle based on input direction
float angle = Mathf.Atan2(y, x) * Mathf.Rad2Deg;
// Apply the rotation to the player
transform.rotation = Quaternion.Euler(0, 0, angle);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e7179393266b4d039813b2dec39dd1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: