Ajout du system de coins et modif de l'obstacle de Paul

This commit is contained in:
louis 2025-01-16 11:54:09 +01:00
parent a9b626b86e
commit cda263839d
16 changed files with 344 additions and 1217 deletions

View File

@ -2,19 +2,26 @@
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: comuter_wall
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _METALLICGLOSSMAP
m_LightmapFlags: 5
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _EMISSION
- _METALLICGLOSSMAP
m_InvalidKeywords: []
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
@ -54,19 +61,26 @@ Material:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.8, g: 0.8, b: 0.8, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aa7ee8fd100668c43a4a6598a35a3ad6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,163 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &9117726010709451998
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2262208576908815080}
- component: {fileID: 3572880127954793139}
- component: {fileID: 6612934893704467973}
- component: {fileID: 2619330802336550126}
- component: {fileID: 6803980266743182291}
- component: {fileID: 6108635676596831665}
- component: {fileID: 1187001800563073841}
m_Layer: 0
m_Name: Coins
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2262208576908815080
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9117726010709451998}
serializedVersion: 2
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 2, z: 0}
m_LocalScale: {x: 1, y: 0.05, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!33 &3572880127954793139
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9117726010709451998}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &6612934893704467973
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9117726010709451998}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 9fc1d0d62308b2a47839d64bc3a4983d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!136 &2619330802336550126
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9117726010709451998}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5000001
m_Height: 2
m_Direction: 1
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697}
--- !u!65 &6803980266743182291
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9117726010709451998}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1.0000001, y: 2.0000005, z: 1.0000005}
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940699}
--- !u!114 &6108635676596831665
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9117726010709451998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ddaf0a1f90e1c46428ba5f029fd32ad0, type: 3}
m_Name:
m_EditorClassIdentifier:
coinValue: 50
--- !u!114 &1187001800563073841
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9117726010709451998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ef8880022572d924bbe4f58655a16a6f, type: 3}
m_Name:
m_EditorClassIdentifier:
amplitude: 0.1
animationVelocity: {x: 0, y: 1, z: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b23a39661488b4b4bb909b4285f3f874
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -104,7 +104,7 @@ BoxCollider:
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 2, y: 2, z: 2}
m_Center: {x: 0, y: 0, z: 0}
m_Center: {x: 0, y: 0.5, z: 0}
--- !u!114 &6632165759313513218
MonoBehaviour:
m_ObjectHideFlags: 0
@ -230,8 +230,8 @@ BoxCollider:
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 2, y: 2, z: 2}
m_Center: {x: 0, y: 0, z: 0}
m_Size: {x: 2, y: 1.75, z: 2}
m_Center: {x: 0, y: 2.25, z: 0}
--- !u!114 &-5363852902891024896
MonoBehaviour:
m_ObjectHideFlags: 0
@ -245,7 +245,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
<IsOnAllLanes>k__BackingField: 0
<IsInevitable>k__BackingField: 1
<IsInevitable>k__BackingField: 0
--- !u!4 &4156031263124959724 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -4216859302048453862, guid: 02c07866f16913044aea6679ce17cfc5, type: 3}

View File

@ -24,13 +24,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1385490266177085035}
serializedVersion: 2
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: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3244299530156243158
MonoBehaviour:
@ -44,5 +44,5 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1290664e863a3d34596917f255587b4c, type: 3}
m_Name:
m_EditorClassIdentifier:
capacity: 30
capacity: 10
prefab: {fileID: 6716018880928220119, guid: aa7da947970bb714fa7924d204fe2bdd, type: 3}

View File

@ -24,13 +24,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4737509690352194895}
serializedVersion: 2
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: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6300939898152622968
MonoBehaviour:
@ -44,5 +44,5 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1290664e863a3d34596917f255587b4c, type: 3}
m_Name:
m_EditorClassIdentifier:
capacity: 20
capacity: 10
prefab: {fileID: 6716018880928220119, guid: aa7da947970bb714fa7924d204fe2bdd, type: 3}

View File

@ -1687,7 +1687,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1290664e863a3d34596917f255587b4c, type: 3}
m_Name:
m_EditorClassIdentifier:
capacity: 30
capacity: 10
prefab: {fileID: -5363852902891024896, guid: 3e76749ffe8f4044db8b25dd6fcdd62d, type: 3}
--- !u!1 &917043515
GameObject:
@ -2188,6 +2188,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
LaneSystem: {fileID: 106057762}
coinPool: {fileID: 1902464044}
<ObstaclePools>k__BackingField:
- {fileID: 4230759379826572186}
- {fileID: 3994382559241916552}
@ -2227,6 +2228,7 @@ Transform:
- {fileID: 916824467}
- {fileID: 1507006778095683194}
- {fileID: 1119912663875091926}
- {fileID: 1902464043}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1237272500
@ -2856,7 +2858,7 @@ AudioSource:
m_audioClip: {fileID: 8300000, guid: ddf8fb13b61f8474d89b050db1febfc6, type: 3}
m_Resource: {fileID: 8300000, guid: ddf8fb13b61f8474d89b050db1febfc6, type: 3}
m_PlayOnAwake: 1
m_Volume: 0.75
m_Volume: 0.05
m_Pitch: 1
Loop: 1
Mute: 0
@ -3462,6 +3464,52 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1899410411}
m_CullTransparentMesh: 1
--- !u!1 &1902464042
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1902464043}
- component: {fileID: 1902464044}
m_Layer: 0
m_Name: Coins
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1902464043
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1902464042}
serializedVersion: 2
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: 1176782784}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1902464044
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1902464042}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c4456a434a6301241bcca08c705b96c4, type: 3}
m_Name:
m_EditorClassIdentifier:
capacity: 1
prefab: {fileID: 6108635676596831665, guid: b23a39661488b4b4bb909b4285f3f874, type: 3}
--- !u!1 &2033098990
GameObject:
m_ObjectHideFlags: 0
@ -3988,7 +4036,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1290664e863a3d34596917f255587b4c, type: 3}
m_Name:
m_EditorClassIdentifier:
capacity: 30
capacity: 10
prefab: {fileID: -2344530007010565835, guid: dd64cf90044eea341a44470119043683, type: 3}
--- !u!224 &4191864465036188526
RectTransform:
@ -4366,7 +4414,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1290664e863a3d34596917f255587b4c, type: 3}
m_Name:
m_EditorClassIdentifier:
capacity: 30
capacity: 10
prefab: {fileID: 5386355404380617402, guid: 5b773f1726a94b948a9e203041402aab, type: 3}
--- !u!1 &7557377091183692521
GameObject:

View File

@ -5,6 +5,7 @@ using UnityEngine;
public class Coin : PoolingObject<Coin>, ICollectable,IResettable
{
[SerializeField] private int coinValue;
public int CoinValue => coinValue;
private SinAnimator sinAnimator;
public Renderer Renderer { get; private set; }
@ -23,7 +24,9 @@ public class Coin : PoolingObject<Coin>, ICollectable,IResettable
gameObject.SetActive(false);
OnCoinCollected?.Invoke(coinValue);
OnCoinDissapeared?.Invoke(this);
ReturnToPool();
}
public void UpdateStartPositionForSinAnimator()
{
sinAnimator.UpdateStartPosition();

View File

@ -115,27 +115,30 @@ public class Player : MonoBehaviour, IResettable, ICommandTranslator
private void OnTriggerEnter(Collider other)
{
if (other.TryGetComponent(out IDamageDealer damageDealer)) //switch..case
if (other.TryGetComponent(out IDamageDealer damageDealer))
{
if (IsInvincible)
return;
if (IsInvincible) return;
int damageAmount = 1;
var damageableComponents = GetComponents<IDamageable>();
foreach (var component in damageableComponents)
foreach (var component in GetComponents<IDamageable>())
{
damageDealer.DealDamage(component, damageAmount);
}
StartCoroutine(GrantInvincibility());
}
if (other.TryGetComponent(out IObstacle obstacle)) //switch..case
if (other.TryGetComponent(out IObstacle obstacle))
{
obstacle.Impact();
}
else if (other.TryGetComponent(out ICollectable collectable))
{
collectable.Collect();
if (other.TryGetComponent(out Coin coin))
{
PlayerStatictics.AddScore(coin.CoinValue);
coin.gameObject.SetActive(false);
}
}
}

View File

@ -54,4 +54,12 @@ public class Statistics : MonoBehaviour,IResettable
coinMultiplier = 1;
//gameOverPopUp.gameObject.SetActive(false);
}
public void AddScore(int amount)
{
Score += amount;
OnScoreCalculated?.Invoke(Score);
PlayerHUD.UpdateScore(Score.ToString());
}
}

View File

@ -1,5 +1,9 @@
using System;
using System.Collections;
using UnityEngine;
public class CoinPool : BasePool<Coin>
{}
namespace Pools
{
public sealed class CoinPool : BasePool<Coin>
{}
}

View File

@ -1,13 +1,13 @@
using Pools;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChunkGenerator : MonoBehaviour
{
[SerializeField] private LaneSystem LaneSystem;
public CoinPool CoinPool { get; private set; }
[SerializeField] private CoinPool coinPool;
[field: SerializeField] public List<ObstaclePool> ObstaclePools { get; private set; }
private bool _isFirstChunk = true;
public Chunk Generate(Chunk chunkToFill)
{
@ -16,21 +16,56 @@ public class ChunkGenerator : MonoBehaviour
_isFirstChunk = false;
return chunkToFill;
}
if (ObstaclePools.IsEmpty())
return chunkToFill;
var obstaclePool = ObstaclePools.GetRandomElement();
var obstacle = obstaclePool.Spawn();
chunkToFill.Obstacles.Add(obstacle);
obstacle.transform.SetParent(chunkToFill.transform, true);
obstacle.transform.localPosition = chunkToFill.Grid.GetRandomPosition();
if (obstacle.IsOnAllLanes)
if (!ObstaclePools.IsEmpty())
{
obstacle.transform.localPosition = new Vector3(
LaneSystem.CenterLane * LaneSystem.LaneWidth,
transform.localPosition.y,
transform.localPosition.z
);
var obstaclePool = ObstaclePools.GetRandomElement();
var obstacle = obstaclePool.Spawn();
chunkToFill.Obstacles.Add(obstacle);
obstacle.transform.SetParent(chunkToFill.transform, true);
obstacle.transform.localPosition = chunkToFill.Grid.GetRandomPosition();
if (obstacle.IsOnAllLanes)
{
obstacle.transform.localPosition = new Vector3(
LaneSystem.CenterLane * LaneSystem.LaneWidth,
transform.localPosition.y,
transform.localPosition.z
);
}
}
Coin coin = coinPool.Spawn();
chunkToFill.Coins.Add(coin);
coin.transform.SetParent(chunkToFill.transform, true);
Vector3 randomPosition;
bool isPositionValid = false;
int laneIndex = Random.Range(0, LaneSystem.LaneCount);
randomPosition = new Vector3(
laneIndex * LaneSystem.LaneWidth,
chunkToFill.Grid.GetRandomPosition().y + 1.0f,
chunkToFill.Grid.GetRandomPosition().z
);
while (!isPositionValid)
{
isPositionValid = true;
foreach (var obstacle in chunkToFill.Obstacles)
{
if (Vector3.Distance(randomPosition, obstacle.transform.localPosition) < 1.0f)
{
isPositionValid = false;
break;
}
}
if (!isPositionValid)
{
randomPosition = new Vector3(
laneIndex * LaneSystem.LaneWidth,
chunkToFill.Grid.GetRandomPosition().y + 1.0f,
chunkToFill.Grid.GetRandomPosition().z
);
}
}
coin.transform.localPosition = randomPosition;
coin.UpdateStartPositionForSinAnimator();
return chunkToFill;
}
}

View File

@ -37,6 +37,7 @@ public abstract class Chunk : PoolingObject<Chunk>, IResettable
transform.localPosition = Vector3.zero;
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
Coins.Clear();
}
private void OnTriggerExit(Collider other)
{

View File

@ -8,6 +8,7 @@ public class LaneSystem : MonoBehaviour,IResettable
[field: SerializeField] public float LaneWidth { get; private set; }
[SerializeField] private int laneCount;
public int LaneCount => laneCount;
public List<int> Lanes { get; private set; }
public float CurrentPosition { get; private set; }
public float TargetPosition { get; set; }

File diff suppressed because one or more lines are too long