Code refactor, added coins chests, key chest and door
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &7047733282028940674
|
||||
--- !u!1 &1975438356756539878
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@@ -8,39 +8,37 @@ GameObject:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7047733282028940670}
|
||||
- component: {fileID: 7047733282028940671}
|
||||
- component: {fileID: 7047733282028940672}
|
||||
- component: {fileID: 7047733282028940673}
|
||||
- component: {fileID: 7713479245319812145}
|
||||
- component: {fileID: 6310184180613926196}
|
||||
m_Layer: 0
|
||||
m_Name: Klad
|
||||
m_Name: Visual
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &7047733282028940670
|
||||
--- !u!4 &7713479245319812145
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7047733282028940674}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -3.49, y: -1.441315, z: 0}
|
||||
m_GameObject: {fileID: 1975438356756539878}
|
||||
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_Father: {fileID: 7047733282028940670}
|
||||
m_RootOrder: -1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &7047733282028940671
|
||||
--- !u!212 &6310184180613926196
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7047733282028940674}
|
||||
m_GameObject: {fileID: 1975438356756539878}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 0
|
||||
m_ReceiveShadows: 0
|
||||
@@ -72,8 +70,8 @@ SpriteRenderer:
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingLayerID: -133646357
|
||||
m_SortingLayer: 2
|
||||
m_SortingOrder: 0
|
||||
m_Sprite: {fileID: 134424294, guid: d4db151fbe2751a408aea21a96ebdd19, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
@@ -86,6 +84,40 @@ SpriteRenderer:
|
||||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!1 &7047733282028940674
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7047733282028940670}
|
||||
- component: {fileID: 7047733282028940672}
|
||||
- component: {fileID: 7047733282028940673}
|
||||
m_Layer: 0
|
||||
m_Name: CoinChest
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &7047733282028940670
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7047733282028940674}
|
||||
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:
|
||||
- {fileID: 7713479245319812145}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!61 &7047733282028940672
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -118,7 +150,7 @@ BoxCollider2D:
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Offset: {x: 0, y: 0.14}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
@@ -129,7 +161,7 @@ BoxCollider2D:
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 1}
|
||||
m_Size: {x: 0.89, y: 1}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &7047733282028940673
|
||||
MonoBehaviour:
|
||||
@@ -0,0 +1,177 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &1975438356756539878
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7713479245319812145}
|
||||
- component: {fileID: 6310184180613926196}
|
||||
m_Layer: 0
|
||||
m_Name: Visual
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &7713479245319812145
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1975438356756539878}
|
||||
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: 7047733282028940670}
|
||||
m_RootOrder: -1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &6310184180613926196
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1975438356756539878}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 0
|
||||
m_ReceiveShadows: 0
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, 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: 0
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: -133646357
|
||||
m_SortingLayer: 2
|
||||
m_SortingOrder: 0
|
||||
m_Sprite: {fileID: 134424294, guid: d4db151fbe2751a408aea21a96ebdd19, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_FlipX: 0
|
||||
m_FlipY: 0
|
||||
m_DrawMode: 0
|
||||
m_Size: {x: 1, y: 1}
|
||||
m_AdaptiveModeThreshold: 0.5
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!1 &7047733282028940674
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 7047733282028940670}
|
||||
- component: {fileID: 7047733282028940672}
|
||||
- component: {fileID: -4675887052017683495}
|
||||
m_Layer: 0
|
||||
m_Name: KeyChest
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &7047733282028940670
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7047733282028940674}
|
||||
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:
|
||||
- {fileID: 7713479245319812145}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!61 &7047733282028940672
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7047733282028940674}
|
||||
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.14}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0.5, y: 0.5}
|
||||
oldSize: {x: 0.8923077, y: 0.6846154}
|
||||
newSize: {x: 1, y: 1}
|
||||
adaptiveTilingThreshold: 0.5
|
||||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 0.89, y: 1}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &-4675887052017683495
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7047733282028940674}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: cf81d521c74041643b3e8f0569c55a0f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b80f7f5da16d785459eef24f81daa678
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1805,7 +1805,7 @@ BoxCollider2D:
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 1
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0, y: 0}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BoxesController : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.tag == "Player")
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Chest : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter2D(Collider2D collider)
|
||||
{
|
||||
var player=collider.GetComponent<Player>();
|
||||
if (player != null)
|
||||
{
|
||||
player.AddCoin();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
public class Door : MonoBehaviour,IDoor
|
||||
{
|
||||
public void OpenDoor()
|
||||
{
|
||||
//PlayOpenAnimation
|
||||
|
||||
//Disable box collider
|
||||
gameObject.GetComponent<BoxCollider2D>().enabled=false;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DoorController : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.tag == "Player")
|
||||
{
|
||||
//if player have key, door will open
|
||||
//else player can't pass
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
public class DoorInteract : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject _doorGameObject;
|
||||
private IDoor _door;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_door =_doorGameObject.GetComponent<IDoor>();
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collider)
|
||||
{
|
||||
var player = collider.GetComponent<Player>();
|
||||
if (player!=null)
|
||||
{
|
||||
if (player.IsHasKey())
|
||||
{
|
||||
_door.OpenDoor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c43502b5415adc044b631292348c83e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,6 +3,5 @@
|
||||
public interface IDoor
|
||||
{
|
||||
void OpenDoor();
|
||||
void ToggleDoor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class KeyChest : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter2D(Collider2D collider)
|
||||
{
|
||||
var player = collider.GetComponent<Player>();
|
||||
if (player != null)
|
||||
{
|
||||
player.SetKey();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf81d521c74041643b3e8f0569c55a0f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator animator;
|
||||
@@ -17,17 +18,41 @@ public class PlayerController : MonoBehaviour
|
||||
private BoxCollider2D _boxCollider;
|
||||
private bool _isFall;
|
||||
private bool _facingRight = true;
|
||||
private bool _haveKey = false;
|
||||
|
||||
private int _totalCoins = 0;
|
||||
private bool _hasKey = false;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
_body = GetComponent<Rigidbody2D>();
|
||||
_boxCollider = GetComponent<BoxCollider2D>();
|
||||
}
|
||||
void Update()
|
||||
|
||||
public void AddCoin()
|
||||
{
|
||||
_totalCoins++;
|
||||
print($"player have {_totalCoins} coins");
|
||||
}
|
||||
|
||||
public void SetKey()
|
||||
{
|
||||
print($"player have key");
|
||||
_hasKey =true;
|
||||
}
|
||||
|
||||
public void RemoveKey()
|
||||
{
|
||||
_hasKey = false;
|
||||
}
|
||||
|
||||
public bool IsHasKey()
|
||||
{
|
||||
return _hasKey;
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float inputHorizontal = 0;
|
||||
float inputVertical = 0;
|
||||
|
||||
var groundCheck = Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, Vector2.down, .1f, groundLayer);
|
||||
@@ -35,7 +60,7 @@ public class PlayerController : MonoBehaviour
|
||||
if (groundCheck || _isOnLadder)
|
||||
{
|
||||
_isFall = false;
|
||||
inputHorizontal = Input.GetAxisRaw("Horizontal");
|
||||
float inputHorizontal = Input.GetAxisRaw("Horizontal");
|
||||
if (inputHorizontal > 0 && !_facingRight)
|
||||
{
|
||||
FlipCharacter();
|
||||
@@ -77,6 +102,8 @@ public class PlayerController : MonoBehaviour
|
||||
return Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, direction, .1f, ladderLayer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (_isOnLadder)
|
||||
@@ -108,12 +135,5 @@ public class PlayerController : MonoBehaviour
|
||||
_facingRight = !_facingRight;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
var door = collision.GetComponent<DoorController>();
|
||||
if (door != null)
|
||||
{
|
||||
door.OpenDoor();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user