Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions GoToLift.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// review(24.05.2024): кажется, что этот класс ничего не делает. Стоит его удалить, чтобы не мешался
public class GoToLift : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
21 changes: 14 additions & 7 deletions Scripts/CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

public class CameraController : MonoBehaviour
{
private float dumping = 1.5f;
public static int sharedValue = 0;
private float dumping = 4f;
private Vector2 offset = new (2f, 1f);
private bool isLeft;

Expand All @@ -22,14 +23,13 @@ public class CameraController : MonoBehaviour
[SerializeField]
private float upperLimit;

// Start is called before the first frame update
void Start()
private void Start()
{
offset = new Vector2(Math.Abs(offset.x), offset.y);
FindPlayer(isLeft);
}

public void FindPlayer(bool playerIsLeft)
private void FindPlayer(bool playerIsLeft)
{
player = GameObject.FindGameObjectsWithTag("Player").First().transform;
lastX = Mathf.RoundToInt(player.position.x);
Expand All @@ -45,10 +45,9 @@ public void FindPlayer(bool playerIsLeft)
}
}

// Update is called once per frame
void Update()
private void Update()
{
if (player)
if (player) // review(24.05.2024): Непонятно, как Transform преобразуется в bool
{
var currentX = Mathf.RoundToInt(player.position.x);
if (currentX > lastX)
Expand All @@ -57,6 +56,7 @@ void Update()
isLeft = true;
lastX = Mathf.RoundToInt(player.position.x);

// review(24.05.2024): тернарником бы лаконичнее смотерлось
Vector3 target;
if (isLeft)
{
Expand All @@ -80,5 +80,12 @@ void Update()
Mathf.Clamp(transform.position.y, bottomLimit, upperLimit),
transform.position.z
);
if (sharedValue == 1) {
var camTransform = GetComponent<Transform>();
var originPos = camTransform.localPosition;
float shakeDur = 1f, shakeAmount = 0.1f, decreaseFact = 1.5f;

camTransform.localPosition = originPos + UnityEngine.Random.insideUnitSphere * shakeAmount;
}
}
}
26 changes: 26 additions & 0 deletions Scripts/CameraFollow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
public static int sharedValue = 0;
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;

void FixedUpdate()
{
if (target != null)
{
var desiredPosition = target.position + offset;
var smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;

transform.position = new Vector3(
Mathf.Clamp(transform.position.x, -13.7f, 6.95f),
Mathf.Clamp(transform.position.y, -10, 10),
transform.position.z
);
}

}
}
25 changes: 25 additions & 0 deletions Scripts/CameraMovement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using UnityEngine;

public class CameraMovement : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;

void FixedUpdate()
{
if (target != null)
{
var desiredPosition = target.position + offset;
var smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;

// review(24.05.2024): Мне тут райдер советует выделить переменную var position = transform.position, ее поменять и присвоить transform.position = position;
transform.position = new Vector3(
Mathf.Clamp(transform.position.x, -13.7f, 6.95f),
Mathf.Clamp(transform.position.y, -10, 10),
transform.position.z
);
}
}
}
21 changes: 21 additions & 0 deletions Scripts/CharacterAnimations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterAnimations : MonoBehaviour
{
private Animator animator;
public bool IsWalking { private get; set; }
public bool IsRunning { private get; set; }

private void Start()
{
animator = GetComponent<Animator>();
}

private void FixedUpdate()
{
animator.SetBool("isWalking", IsWalking);
animator.SetBool("isRunning", IsRunning);
}
}
44 changes: 44 additions & 0 deletions Scripts/CharacterMovement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterMovement : MonoBehaviour
{
[SerializeField] private float speed;
private Vector3 input;
private bool isWalking;
private bool isRunning;
private Animator animator;
private CharacterAnimations animations;
[SerializeField] private SpriteRenderer characterSprite;

private void Start()
{
animator = GetComponent<Animator>();
animations = GetComponentInChildren<CharacterAnimations>();
}

private void FixedUpdate() => Move();

// review(24.05.2024): Я уже видел этот код в PlayerController
private void Move()
{
input = new Vector2(Input.GetAxis("Horizontal"), 0);
isWalking = input.x != 0;
isRunning = input.x != 0 && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));

if (isWalking || isRunning)
{
var animationToPlay = isRunning ? "Run" : "Walk";
var movementSpeed = isRunning ? 3f * speed : speed;
animator.Play(animationToPlay);
characterSprite.flipX = input.x > 0;
transform.position += input * (movementSpeed * Time.deltaTime);
}
else
animator.Play("Calm");

animations.IsWalking = isWalking;
animations.IsRunning = isRunning;
}
}
36 changes: 36 additions & 0 deletions Scripts/Fear.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fear : MonoBehaviour
{
// review(24.05.2024): Публичное статическое изменяемое поле, хм... Можем ли мы хотя бы методами его закрыть?
// review(24.05.2024): Ну и название непонятноеы
public static int sharedValue = 0;
public int saved = 0; // review(24.05.2024): Почему оно публичное? Может, это previousFear?
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
if (saved != sharedValue)
{
saved = sharedValue;
if (sharedValue == 1)
{
//Camera.main.gameObject.AddComponent<CameraShake>();
GetComponent<AudioSource>().Play();
CameraController.sharedValue = 1; // review(24.05.2024): Может, лучше в CameraController обращаться к Fear.sharedValue, чтобы был только один источник правды?
}
else if (sharedValue == 0) {
GetComponent<AudioSource>().Pause();
CameraController.sharedValue = 0;
}
}

}
}
4 changes: 3 additions & 1 deletion Scripts/FlashSW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;

// review(24.05.2024): Дайте полям нормальные названия
public class FlashSW : MonoBehaviour
{

Expand All @@ -17,7 +18,8 @@ void Start()
// Update is called once per frame
void Update()
{
if (Input.GetKeyUp(FLC)){
if (Input.GetKeyUp(FLC))
{
FL.enabled = ! FL.enabled;
GetComponent<AudioSource>().PlayOneShot(FLS);
}
Expand Down
Loading