Added a custom cursor
This commit is contained in:
@@ -911,6 +911,7 @@ RectTransform:
|
||||
m_Children:
|
||||
- {fileID: 1944344878}
|
||||
- {fileID: 2112507919}
|
||||
- {fileID: 1330313875}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
@@ -1076,6 +1077,133 @@ CanvasRenderer:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1326837323}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &1330313874
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1330313875}
|
||||
- component: {fileID: 1330313877}
|
||||
- component: {fileID: 1330313876}
|
||||
- component: {fileID: 1330313878}
|
||||
- component: {fileID: 1330313879}
|
||||
m_Layer: 5
|
||||
m_Name: GameCursor
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &1330313875
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1330313874}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1165634414}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 60, y: 60}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &1330313876
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1330313874}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 0, b: 0, a: 1}
|
||||
m_RaycastTarget: 0
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 0}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!222 &1330313877
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1330313874}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!114 &1330313878
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1330313874}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4c69710c42ff4ee0bb660893e59c12fe, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
ActiveCamera: {fileID: 330585545}
|
||||
CursorCollider: {fileID: 1330313879}
|
||||
RectTransform: {fileID: 1330313875}
|
||||
--- !u!58 &1330313879
|
||||
CircleCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1330313874}
|
||||
m_Enabled: 1
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.5
|
||||
--- !u!1 &1347333876
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using PashaBibko.Pacore.Attributes;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Fruitomation
|
||||
{
|
||||
@@ -23,12 +24,8 @@ namespace Fruitomation
|
||||
Spawner = spawner;
|
||||
|
||||
Body2D.velocity = Random.insideUnitCircle * 2.5f;
|
||||
|
||||
Button.onClick.AddListener(OnPlayerClicked);
|
||||
}
|
||||
|
||||
private void OnPlayerClicked() => TriggerDestruction();
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!GameStateController.Is(GameState.Simulation))
|
||||
@@ -48,7 +45,7 @@ namespace Fruitomation
|
||||
}
|
||||
}
|
||||
|
||||
private void TriggerDestruction()
|
||||
public void TriggerDestruction()
|
||||
{
|
||||
MoneyController.Add((ulong)Random.Range(1, 5));
|
||||
|
||||
|
||||
78
Assets/Scripts/GameCursor.cs
Normal file
78
Assets/Scripts/GameCursor.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Fruitomation
|
||||
{
|
||||
public class GameCursor : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private Camera ActiveCamera;
|
||||
[SerializeField] private CircleCollider2D CursorCollider;
|
||||
[SerializeField] private RectTransform RectTransform;
|
||||
|
||||
private readonly ContactFilter2D ContactFilter = new();
|
||||
private readonly List<Collider2D> Colliders = new();
|
||||
|
||||
private float CurrentMouseClickStrength;
|
||||
private float StartOfMouseClick;
|
||||
|
||||
private void UpdatePosition()
|
||||
{
|
||||
Ray ray = ActiveCamera.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
float t = -ray.origin.z / ray.direction.z;
|
||||
Vector2 position = ray.origin + t * ray.direction;
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
private void UpdateMouseState()
|
||||
{
|
||||
const float MIN_STRENGTH = 0.5f;
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
CurrentMouseClickStrength = MIN_STRENGTH;
|
||||
|
||||
CursorCollider.radius = CurrentMouseClickStrength * 30f;
|
||||
Physics2D.OverlapCollider(CursorCollider, ContactFilter, Colliders);
|
||||
|
||||
foreach (Collider2D col in Colliders)
|
||||
{
|
||||
if (col.transform.name == "Sprite")
|
||||
{
|
||||
FruitBehaviour fruit = col.GetComponentInParent<FruitBehaviour>();
|
||||
Debug.Assert(fruit != null, "Couldn't find FruitBehaviour");
|
||||
|
||||
fruit.TriggerDestruction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
StartOfMouseClick = Time.time;
|
||||
CurrentMouseClickStrength = MIN_STRENGTH;
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentMouseClickStrength = Time.time - StartOfMouseClick;
|
||||
CurrentMouseClickStrength = Mathf.Clamp(CurrentMouseClickStrength, MIN_STRENGTH, 1.7f);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
CurrentMouseClickStrength = MIN_STRENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateMouseState();
|
||||
UpdatePosition();
|
||||
|
||||
RectTransform.localScale = new Vector3(CurrentMouseClickStrength, CurrentMouseClickStrength, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/GameCursor.cs.meta
Normal file
3
Assets/Scripts/GameCursor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c69710c42ff4ee0bb660893e59c12fe
|
||||
timeCreated: 1774874748
|
||||
Reference in New Issue
Block a user