diff --git a/Assets/GameData/Action/Abilities/Vector Fence.asset b/Assets/GameData/Action/Abilities/Vector Fence.asset index 05f8815..979f185 100644 --- a/Assets/GameData/Action/Abilities/Vector Fence.asset +++ b/Assets/GameData/Action/Abilities/Vector Fence.asset @@ -19,7 +19,7 @@ MonoBehaviour: abilityDuration: 5 abilityCooldownTime: 3 prefab: {fileID: 9694722736535169, guid: 9b94ed8895919e84aa669628b0761eaf, type: 3} - wallLength: 7 + wallLength: 8 wallWidth: 0.5 - wallHeight: 1 + wallHeight: 2 scaleUpDuration: 1 diff --git a/Assets/Material/InvalidPlacmentMaterial.mat b/Assets/Material/InvalidPlacmentMaterial.mat new file mode 100644 index 0000000..ebd9f69 --- /dev/null +++ b/Assets/Material/InvalidPlacmentMaterial.mat @@ -0,0 +1,137 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: InvalidPlacmentMaterial + m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: + - _ALPHAPREMULTIPLY_ON + - _SURFACE_TYPE_TRANSPARENT + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: 3000 + stringTagMap: + RenderType: Transparent + disabledShaderPasses: + - DepthOnly + - SHADOWCASTER + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AlphaClip: 0 + - _AlphaToMask: 0 + - _Blend: 2 + - _BlendModePreserveSpecular: 1 + - _BumpScale: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 1 + - _DstBlendAlpha: 1 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _Smoothness: 0.5 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SrcBlendAlpha: 1 + - _Surface: 1 + - _WorkflowMode: 1 + - _ZWrite: 0 + m_Colors: + - _BaseColor: {r: 1, g: 0, b: 0.100675575, a: 0.8235294} + - _Color: {r: 1, g: 0, b: 0.100675546, a: 0.8235294} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + m_BuildTextureStacks: [] +--- !u!114 &4405473290192554091 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 7 diff --git a/Assets/Material/InvalidPlacmentMaterial.mat.meta b/Assets/Material/InvalidPlacmentMaterial.mat.meta new file mode 100644 index 0000000..488d726 --- /dev/null +++ b/Assets/Material/InvalidPlacmentMaterial.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 17c37eab78656344ebb7bb5c1657b81c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Character/PlayerAvatar.prefab b/Assets/Prefabs/Character/PlayerAvatar.prefab index ce55f56..2daac35 100644 --- a/Assets/Prefabs/Character/PlayerAvatar.prefab +++ b/Assets/Prefabs/Character/PlayerAvatar.prefab @@ -264,7 +264,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4600110157238723790, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} propertyPath: GlobalObjectIdHash - value: 3177087589 + value: 3737985212 objectReference: {fileID: 0} - target: {fileID: 4600110157238723790, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3} propertyPath: PrefabHashGenerator @@ -840,6 +840,12 @@ MonoBehaviour: - {fileID: 11400000, guid: 834f18926d3364d40ab9894f716b4e3b, type: 2} currentAbilityIndicator: {fileID: 92142163933926358} wallIndicator: {fileID: 1257869342993333690} + validPlacementMaterial: {fileID: 2100000, guid: 3a415e4b90d5e7346a544b94fa0f34bd, type: 2} + invalidPlacementMaterial: {fileID: 2100000, guid: 17c37eab78656344ebb7bb5c1657b81c, type: 2} + wallRotationSpeed: 1.2 + playerLayer: + serializedVersion: 2 + m_Bits: 8 --- !u!114 &4321537148236331373 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Gameplay/AbilitySystem.cs b/Assets/Scripts/Gameplay/AbilitySystem.cs index 0074e9d..02ef000 100644 --- a/Assets/Scripts/Gameplay/AbilitySystem.cs +++ b/Assets/Scripts/Gameplay/AbilitySystem.cs @@ -17,12 +17,16 @@ public class AbilitySystem : NetworkBehaviour [SerializeField] private GameObject currentAbilityIndicator; [SerializeField] private GameObject wallIndicator; + [SerializeField] private Material validPlacementMaterial; + [SerializeField] private Material invalidPlacementMaterial; [Header("Wall Placement Settings")] [SerializeField] private float wallRotationSpeed = 1.2f; + [SerializeField] private LayerMask playerLayer; // Layer for detecting players private Vector3 wallSpawnPosition; private bool isWallPlacementStarted = false; + private bool isValidPlacement = true; void Update() { @@ -42,7 +46,7 @@ public class AbilitySystem : NetworkBehaviour UpdateWallIndicatorPosition(); // Follow the mouse when ability is activated } - if (Input.GetMouseButtonDown(0)) + if (Input.GetMouseButtonDown(0) && isValidPlacement) { StartWallPlacement(); } @@ -54,8 +58,15 @@ public class AbilitySystem : NetworkBehaviour if (Input.GetMouseButtonUp(0) && isWallPlacementStarted) { - UseActiveAbility(); // Place the wall when LMB is released - isWallPlacementStarted = false; + if (isValidPlacement) + { + UseActiveAbility(); // Place the wall when LMB is released + isWallPlacementStarted = false; + } + else + { + Debug.Log("Invalid placement! Cannot place wall on top of another player."); + } } } else @@ -94,16 +105,44 @@ public class AbilitySystem : NetworkBehaviour if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit)) { wallIndicator.transform.position = hit.point; // Update position to follow the mouse + + // Calculate half-extents based on wall's current scale + Vector3 halfExtents = new Vector3( + wallIndicator.transform.localScale.x / 2f, + wallIndicator.transform.localScale.y / 2f, + wallIndicator.transform.localScale.z / 2f + ); + + // Perform BoxCast aligned with the wall's orientation + isValidPlacement = !Physics.CheckBox( + hit.point, + halfExtents, + wallIndicator.transform.rotation, + playerLayer + ); + // Change indicator color based on placement validity + var meshRenderer = wallIndicator.GetComponent(); + if (meshRenderer != null) + { + meshRenderer.material = isValidPlacement ? validPlacementMaterial : invalidPlacementMaterial; + } } } - + private void StartWallPlacement() { if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit)) { - wallSpawnPosition = hit.point; // Save spawn position - isWallPlacementStarted = true; - Debug.Log($"[AbilitySystem] Wall placement started at {wallSpawnPosition}"); + if (isValidPlacement) + { + wallSpawnPosition = hit.point; // Save spawn position + isWallPlacementStarted = true; + Debug.Log($"[AbilitySystem] Wall placement started at {wallSpawnPosition}"); + } + else + { + Debug.Log("Cannot place the wall on top of another player."); + } } } @@ -122,7 +161,6 @@ public class AbilitySystem : NetworkBehaviour } } - private void ManageStandardAbilityIndicator() { if (currentAbilityIndicator != null)