Commit eef0147c authored by Markus Schlösser's avatar Markus Schlösser
Browse files

Added trigger component and collision with player

parent d6211312
......@@ -22,9 +22,11 @@ GameObject:
- component: {fileID: 212359673814677190}
- component: {fileID: 114577748845638106}
- component: {fileID: 95392249558912674}
m_Layer: 0
- component: {fileID: 61584142457606378}
- component: {fileID: 50515695088472832}
m_Layer: 9
m_Name: Player
m_TagString: Untagged
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......@@ -37,7 +39,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 4547148712663108}
m_Layer: 0
m_Layer: 9
m_Name: Tracking Point
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -71,6 +73,51 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &50515695088472832
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1170495321650788}
m_BodyType: 1
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 1
m_Constraints: 0
--- !u!61 &61584142457606378
BoxCollider2D:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1170495321650788}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.95, y: 0.95}
m_EdgeRadius: 0
--- !u!95 &95392249558912674
Animator:
serializedVersion: 3
......@@ -139,8 +186,8 @@ SpriteRenderer:
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingLayerID: -1398306507
m_SortingLayer: 4
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: d2823e2467bfc464e85b11b9a7867dea, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
......
......@@ -13,3 +13,4 @@ MonoBehaviour:
m_EditorClassIdentifier:
jump: 32
peek: 304
interaction: 13
public interface IInteractible {
void Interact();
}
fileFormatVersion: 2
guid: 27dec4cd9582d5f478ba7216b8dcbac7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,4 +5,5 @@ public abstract class InputProvider : ScriptableObject {
public abstract bool JumpPressed { get; }
public abstract bool PeekingPressed { get; }
public abstract bool InteractionPressed { get; }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class InteractibleTrigger : MonoBehaviour, IInteractible {
[SerializeField] private Orientation orientation;
[SerializeField] private UnityEvent onInteract;
private PlayerActor player;
private void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Player")) {
player = other.GetComponent<PlayerActor>();
if(player != null) {
player.Interactible = this;
}
}
}
private void OnTriggerExit2D(Collider2D other) {
if (player != null) {
player.Interactible = null;
}
}
public void Interact() {
if (player.Orientation == orientation) {
onInteract.Invoke();
}
}
public void Test() {
Debug.Log("Test");
}
}
fileFormatVersion: 2
guid: 88bdb6679bb03b94e89e6710a79f061e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -4,10 +4,13 @@
public class KeyCodeInputProvider : InputProvider {
[SerializeField] private KeyCode jump;
[SerializeField] private KeyCode peek;
[SerializeField] private KeyCode interaction;
public override Vector2 MoveDirection => new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
public override bool JumpPressed => Input.GetKeyDown(jump);
public override bool PeekingPressed => Input.GetKey(peek);
public override bool InteractionPressed => Input.GetKeyDown(interaction);
}
......@@ -18,6 +18,10 @@ public class PlayerActor : MonoBehaviour {
private Coroutine movementRoutine;
public IInteractible Interactible { get; set; }
public Orientation Orientation => orientation;
private enum MovementDirection {
Left = -1,
Right = 1
......@@ -51,6 +55,10 @@ public class PlayerActor : MonoBehaviour {
transform.position = tilemap.GetCellCenterWorld(tilemap.WorldToCell(transform.position));
if (inputProvider.InteractionPressed) {
Interactible.Interact();
}
IEnumerator movement = GetMovementOperation();
if (movement != null) {
movementRoutine = StartCoroutine(movement);
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerTrigger : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
fileFormatVersion: 2
guid: 9cd430fb2c8ca37469ea84c38315c073
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!19 &1
Physics2DSettings:
m_ObjectHideFlags: 0
serializedVersion: 3
m_Gravity: {x: 0, y: -9.81}
m_DefaultMaterial: {fileID: 0}
m_VelocityIterations: 8
m_PositionIterations: 3
m_VelocityThreshold: 1
m_MaxLinearCorrection: 0.2
m_MaxAngularCorrection: 8
m_MaxTranslationSpeed: 100
m_MaxRotationSpeed: 360
m_BaumgarteScale: 0.2
m_BaumgarteTimeOfImpactScale: 0.75
m_TimeToSleep: 0.5
m_LinearSleepTolerance: 0.01
m_AngularSleepTolerance: 2
m_DefaultContactOffset: 0.01
m_AutoSimulation: 1
m_QueriesHitTriggers: 1
m_QueriesStartInColliders: 1
m_ChangeStopsCallbacks: 0
m_CallbacksOnDisable: 1
m_AutoSyncTransforms: 1
m_AlwaysShowColliders: 0
m_ShowColliderSleep: 1
m_ShowColliderContacts: 0
m_ShowColliderAABB: 0
m_ContactArrowScale: 0.2
m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!19 &1
Physics2DSettings:
m_ObjectHideFlags: 0
serializedVersion: 3
m_Gravity: {x: 0, y: -9.81}
m_DefaultMaterial: {fileID: 0}
m_VelocityIterations: 8
m_PositionIterations: 3
m_VelocityThreshold: 1
m_MaxLinearCorrection: 0.2
m_MaxAngularCorrection: 8
m_MaxTranslationSpeed: 100
m_MaxRotationSpeed: 360
m_BaumgarteScale: 0.2
m_BaumgarteTimeOfImpactScale: 0.75
m_TimeToSleep: 0.5
m_LinearSleepTolerance: 0.01
m_AngularSleepTolerance: 2
m_DefaultContactOffset: 0.01
m_JobOptions:
serializedVersion: 2
useMultithreading: 0
useConsistencySorting: 0
m_InterpolationPosesPerJob: 100
m_NewContactsPerJob: 30
m_CollideContactsPerJob: 100
m_ClearFlagsPerJob: 200
m_ClearBodyForcesPerJob: 200
m_SyncDiscreteFixturesPerJob: 50
m_SyncContinuousFixturesPerJob: 50
m_FindNearestContactsPerJob: 100
m_UpdateTriggerContactsPerJob: 100
m_IslandSolverCostThreshold: 100
m_IslandSolverBodyCostScale: 1
m_IslandSolverContactCostScale: 10
m_IslandSolverJointCostScale: 10
m_IslandSolverBodiesPerJob: 50
m_IslandSolverContactsPerJob: 50
m_AutoSimulation: 1
m_QueriesHitTriggers: 1
m_QueriesStartInColliders: 1
m_CallbacksOnDisable: 1
m_AutoSyncTransforms: 1
m_AlwaysShowColliders: 0
m_ShowColliderSleep: 1
m_ShowColliderContacts: 0
m_ShowColliderAABB: 0
m_ContactArrowScale: 0.2
m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: c8f8ffffc8f8ffffc8f8ffffffffffffc8f8ffffc8f8ffffffffffffffffffffc8f8ffffc8fcffffc8faffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
......@@ -16,8 +16,8 @@ TagManager:
-
-
- PostProcessing
-
-
- Player
- Interactible
-
-
-
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment