Skip to content

Commit c792a42

Browse files
committed
Bag Fix and Camera Movment
1 parent 6388a8c commit c792a42

File tree

11 files changed

+626
-56
lines changed

11 files changed

+626
-56
lines changed

Assets/Scenes/MainScene.unity

Lines changed: 457 additions & 49 deletions
Large diffs are not rendered by default.

Assets/Scripts/Code/Camera.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using DG.Tweening;
2+
using UnityEngine;
3+
using UnityEngine.EventSystems;
4+
5+
public class CameraMovement : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUpHandler
6+
{
7+
private const string idCamera = "Camera";
8+
private Camera cameraForMove;
9+
[SerializeField] private float duration = 1;
10+
[SerializeField] private float startSpeed = 3;
11+
private float speed = 1;
12+
private Vector2 startPosition;
13+
private Vector2 direction;
14+
private Vector2 lastNormal;
15+
private void Start()
16+
{
17+
cameraForMove = Camera.main;
18+
speed = startSpeed;
19+
}
20+
public void OnPointerDown(PointerEventData eventData)
21+
{
22+
if (cameraForMove == null)
23+
return;
24+
DOTween.Kill(idCamera);
25+
startPosition = cameraForMove.ScreenToWorldPoint(eventData.position);
26+
}
27+
28+
public void OnDrag(PointerEventData eventData)
29+
{
30+
if (cameraForMove == null)
31+
return;
32+
RaycastHit hit;
33+
Ray ray = new Ray(cameraForMove.transform.position, cameraForMove.transform.forward * 1000);
34+
Debug.DrawRay(cameraForMove.transform.position, cameraForMove.transform.forward * 1000, Color.red);
35+
36+
if (Physics.Raycast(ray, out hit))
37+
{
38+
if (hit.collider.TryGetComponent(out CameraZone zone))
39+
{
40+
lastNormal = cameraForMove.transform.position;
41+
speed = startSpeed;
42+
Debug.Log("ïëîõî");
43+
}
44+
speed = 0.5f*startSpeed;
45+
}
46+
else
47+
{
48+
return;
49+
}
50+
direction = startPosition - (Vector2)cameraForMove.ScreenToWorldPoint(eventData.position);
51+
cameraForMove.transform.Translate(-direction * speed);
52+
startPosition = cameraForMove.ScreenToWorldPoint(eventData.position);
53+
54+
}
55+
56+
public void OnPointerUp(PointerEventData eventData)
57+
{
58+
if (cameraForMove == null)
59+
return;
60+
RaycastHit hit;
61+
Ray ray = new Ray(cameraForMove.transform.position, cameraForMove.transform.forward * 1000);
62+
Debug.Log("ðèñóåì");
63+
Debug.DrawRay(cameraForMove.transform.position, cameraForMove.transform.forward * 1000, Color.red);
64+
65+
if (Physics.Raycast(ray, out hit))
66+
{
67+
if (hit.collider.TryGetComponent(out CameraStopZone zone))
68+
{
69+
cameraForMove.transform.DOMove(new Vector3(lastNormal.x, lastNormal.y, cameraForMove.transform.position.z), duration).SetId(idCamera);
70+
speed = startSpeed;
71+
}
72+
}
73+
else
74+
{
75+
DOTween.Kill(idCamera);
76+
cameraForMove.transform.DOMove(new Vector3(lastNormal.x, lastNormal.y, cameraForMove.transform.position.z), duration).SetId(idCamera);
77+
Debug.Log("íîðì");
78+
}
79+
}
80+
}

Assets/Scripts/Code/Camera/CameraMovement.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class CameraStopZone : MonoBehaviour
6+
{
7+
// Start is called before the first frame update
8+
void Start()
9+
{
10+
11+
}
12+
13+
// Update is called once per frame
14+
void Update()
15+
{
16+
17+
}
18+
}

Assets/Scripts/Code/Camera/CameraStopZone.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class CameraZone : MonoBehaviour
6+
{
7+
// Start is called before the first frame update
8+
void Start()
9+
{
10+
11+
}
12+
13+
// Update is called once per frame
14+
void Update()
15+
{
16+
17+
}
18+
}

Assets/Scripts/Code/Camera/CameraZone.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Code/StartGame/StartGame.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ private void Start()
2828
}
2929
public void OnPlayClick()
3030
{
31-
startGame.DOFade(0, durationFade).OnKill(() => {
31+
startGame.DOFade(0, durationFade).OnKill(() =>
32+
{
3233
_canvasController.AllDefaultPanelActivate();
3334
_canvasController.Setter.TurnOffCanvasGroup(startGame);
3435
_history.OnStartGame();

Assets/Scripts/Code/StartGame/StartGameBar.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ public class StartGameBar : MonoBehaviour
99
[SerializeField] private CanvasGroup playButton;
1010
[SerializeField] private float duration;
1111
[SerializeField] private float durationBauutonFade;
12+
private static bool _isFirstTime = true;
1213
private void Start()
1314
{
15+
if (!_isFirstTime)
16+
return;
17+
_isFirstTime = false;
1418
bar.DOFillAmount(1, duration).SetEase(Ease.OutSine)
15-
.OnKill(()=>playButton.DOFade(1,durationBauutonFade).OnKill(() =>
16-
{
17-
playButton.interactable = true;
18-
playButton.blocksRaycasts = true;
19-
}).SetEase(Ease.InSine));
19+
.OnKill(() => playButton.DOFade(1, durationBauutonFade).OnKill(() =>
20+
{
21+
playButton.interactable = true;
22+
playButton.blocksRaycasts = true;
23+
}).SetEase(Ease.InSine));
2024
}
2125
}

0 commit comments

Comments
 (0)