Cyberpunk: Pathfinder
About
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private Rigidbody2D rb;
private BoxCollider2D coll;
private SpriteRenderer sprite;
private Animator anim;
[SerializeField] private LayerMask jumpableGround;
private float dirX = 0f;
[SerializeField] private float moveSpeed = 7f;
[SerializeField] private float jumpForce = 14f;
private enum MovementState { idle, running, jumping, falling }
[SerializeField] private AudioSource jumpSoundEffect;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
coll = GetComponent<BoxCollider2D>();
sprite = GetComponent<SpriteRenderer>();
anim = GetComponent<Animator>();
}
private void Update()
{
dirX = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(dirX * moveSpeed, rb.velocity.y);
if (Input.GetButtonDown("Jump") && IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
jumpSoundEffect.Play();
}
UpdateAnimationState();
}
private void UpdateAnimationState()
{
MovementState state;
if (dirX > 0f)
{
state = MovementState.running;
sprite.flipX = false;
}
else if (dirX < 0f)
{
state = MovementState.running;
sprite.flipX = true;
}
else
{
state = MovementState.idle;
}
if (rb.velocity.y > .1f)
{
state = MovementState.jumping;
}
else if (rb.velocity.y < -.1f)
{
state = MovementState.falling;
}
anim.SetInteger("state", (int)state);
}
private bool IsGrounded()
{
return Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, .1f, jumpableGround);
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine; public class cameracontroller : MonoBehaviour { [SerializeField] private Transform player; private void Update() { transform.position = new Vector3(player.position.x, player.position.y, transform.position.z); } }
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Finish : MonoBehaviour { private AudioSource finishSound; private bool levelCompleted = false; private void Start() { finishSound = GetComponent<audiosource>(); } private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.name == "Player" && !levelCompleted) { finishSound.Play(); levelCompleted = true; Invoke("CompleteLevel", 2f); } } private void CompleteLevel() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); } } </audiosource>
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class ItemCollector : MonoBehaviour { private int cherries = 0; [SerializeField] private TextMeshProUGUI cherriesText; [SerializeField] private AudioSource collectionSoundEffect; private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Cherry")) { collectionSoundEffect.Play(); Destroy(collision.gameObject); cherries++; cherriesText.text = "Cherries: " + cherries; } } }
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PlayerLife : MonoBehaviour { private Rigidbody2D rb; private Animator anim; [SerializeField] private AudioSource deathSoundEffect; private void Start() { rb = GetComponent<rigidbody2d>(); anim = GetComponent<animator>(); } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Trap")) { Die(); } } private void Die() { deathSoundEffect.Play(); rb.bodyType = RigidbodyType2D.Static; anim.SetTrigger("death"); } private void RestartLevel() { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } </animator></rigidbody2d>
using System.Collections; using System.Collections.Generic; using UnityEngine; public class StickyPlatform : MonoBehaviour { private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.name == "Player") { collision.gameObject.transform.SetParent(transform); } } private void OnCollisionExit2D(Collision2D collision) { if (collision.gameObject.name == "Player") { collision.gameObject.transform.SetParent(null); } } }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class WaypointFollwer : MonoBehaviour { [SerializeField] private GameObject[] waypoints; private int currentWaypointIndex = 0; [SerializeField] private float speed = 4f; private void Update() { if (Vector2.Distance(waypoints[currentWaypointIndex].transform.position, transform.position) < .1f) { currentWaypointIndex++; if (currentWaypointIndex >= waypoints.Length) { currentWaypointIndex = 0; } } transform.position = Vector2.MoveTowards(transform.position, waypoints[currentWaypointIndex].transform.position, Time.deltaTime * speed); } }
System requirements for Web
Last Modified: Feb 3, 2023
Where to buy
itch.io