initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System.Security.Cryptography;
|
||||
using UnityEngine;
|
||||
|
||||
public class Collectible : MonoBehaviour
|
||||
{
|
||||
public float rotationSpeed;
|
||||
public GameObject onCollectEffect;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.Rotate(0, rotationSpeed, 0);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
// Check on Player
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
// Destroy the collectible
|
||||
Destroy(gameObject);
|
||||
|
||||
// instantiate the particle effect
|
||||
Instantiate(onCollectEffect, transform.position, transform.rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8340aab721ae84e4aa0ace2beca61997
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DayNightCycle : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Duration of a full day in seconds")]
|
||||
public float secondsPerDay = 120f;
|
||||
|
||||
private float rotationPerSecond;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Calculate how many degrees the light should rotate per second
|
||||
rotationPerSecond = 360f / secondsPerDay;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Rotate around the X-axis
|
||||
transform.Rotate(Vector3.right, rotationPerSecond * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 706b73f8f9c45904cb7351d91bf9211e
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class DoorOpener : MonoBehaviour
|
||||
{
|
||||
private Animator doorAnimator;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Get the Animator component attached to the same GameObject as this script
|
||||
doorAnimator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
// Check if the object entering the trigger is the player (or another specified object)
|
||||
if (other.CompareTag("Player")) // Make sure the player GameObject has the tag "Player"
|
||||
{
|
||||
if (doorAnimator != null)
|
||||
{
|
||||
// Trigger the Door_Open animation
|
||||
doorAnimator.SetTrigger("Door_Open");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fe562da1152b6f48b87cf4ba5bafec1
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Specialized;
|
||||
using UnityEngine;
|
||||
|
||||
// Controls player movement and rotation.
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public float speed = 5.0f; // Set player's movement speed.
|
||||
public float rotationSpeed = 120.0f; // Set player's rotation speed.
|
||||
public float jumpForce = 5.0f;
|
||||
|
||||
private Rigidbody rb; // Reference to player's Rigidbody.
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>(); // Access player's Rigidbody.
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButtonDown("Jump"))
|
||||
{
|
||||
rb.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle physics-based movement and rotation.
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// Move player based on vertical input.
|
||||
float moveVertical = Input.GetAxis("Vertical");
|
||||
Vector3 movement = transform.forward * moveVertical * speed * Time.fixedDeltaTime;
|
||||
rb.MovePosition(rb.position + movement);
|
||||
|
||||
// Rotate player based on horizontal input.
|
||||
float turn = Input.GetAxis("Horizontal") * rotationSpeed * Time.fixedDeltaTime;
|
||||
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
|
||||
rb.MoveRotation(rb.rotation * turnRotation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ec628da6382d60469c831f723170bfd
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f191f68b56ed64c63a3d95a05dea9556
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
Reference in New Issue
Block a user