Basic oject interaction login

This commit is contained in:
BuyMyMojo 2023-02-28 02:44:39 +11:00
parent d216580bca
commit 2d2eb7d32f
8 changed files with 370 additions and 134 deletions

8
Assets/Prefabs.meta Normal file
View file

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

View file

@ -0,0 +1,148 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6869097019740516189
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6371086230447438899}
- component: {fileID: 190913029279232345}
- component: {fileID: 7837983985068458341}
m_Layer: 6
m_Name: ClearCounter
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6371086230447438899
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6869097019740516189}
m_LocalRotation: {x: -0, y: -0.999996, z: -0, w: -0.0028347075}
m_LocalPosition: {x: -0.000021893527, y: 0, z: 3.0077405}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3231759315905380366}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: -180.325, z: 0}
--- !u!65 &190913029279232345
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6869097019740516189}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1.5, y: 1.5, z: 1.5}
m_Center: {x: 0, y: 0.5, z: 0}
--- !u!114 &7837983985068458341
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6869097019740516189}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bb159edc225081c408fe7a01d52732e4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1398491922627355813
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 6371086230447438899}
m_Modifications:
- target: {fileID: 4589716710238282922, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_Name
value: ClearCounter_Visual
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0004cb1e11ad014419b943c7da960724, type: 3}
--- !u!4 &3231759315905380366 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
m_PrefabInstance: {fileID: 1398491922627355813}
m_PrefabAsset: {fileID: 0}

View file

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

View file

@ -124,6 +124,79 @@ NavMeshSettings:
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
--- !u!1001 &295568153
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_RootOrder
value: 8
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalPosition.x
value: -1.5000219
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalPosition.z
value: 3.0077405
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalRotation.w
value: -0.0028347075
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalRotation.y
value: -0.999996
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: -180.325
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6869097019740516189, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_Name
value: ClearCounter (1)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f62bfcbfbc8097441a9fae9a02652a07, type: 3}
--- !u!1 &330585543 --- !u!1 &330585543
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -666,6 +739,9 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 7 moveSpeed: 7
gameInput: {fileID: 721208334} gameInput: {fileID: 721208334}
countersLayerMask:
serializedVersion: 2
m_Bits: 64
--- !u!1001 &1075657335 --- !u!1001 &1075657335
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -909,139 +985,6 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1262360141
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1573310043}
m_Modifications:
- target: {fileID: 4589716710238282922, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_Name
value: ClearCounter_Visual
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0004cb1e11ad014419b943c7da960724, type: 3}
--- !u!4 &1262360142 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4589716710238282923, guid: 0004cb1e11ad014419b943c7da960724,
type: 3}
m_PrefabInstance: {fileID: 1262360141}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1573310041
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1573310043}
- component: {fileID: 1573310042}
m_Layer: 0
m_Name: ClearCounter
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &1573310042
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1573310041}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1.5, y: 1.5, z: 1.5}
m_Center: {x: 0, y: 0.5, z: 0}
--- !u!4 &1573310043
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1573310041}
m_LocalRotation: {x: -0, y: -0.999996, z: -0, w: -0.0028347075}
m_LocalPosition: {x: -0.000021893527, y: 0, z: 3.0077405}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1262360142}
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: -180.325, z: 0}
--- !u!1 &2099865127 --- !u!1 &2099865127
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1114,3 +1057,76 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 5 m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 46, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 46, y: 0, z: 0}
--- !u!1001 &8218183545890461205
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalPosition.x
value: -0.000021893527
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalPosition.z
value: 3.0077405
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalRotation.w
value: -0.0028347075
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalRotation.y
value: -0.999996
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: -180.325
objectReference: {fileID: 0}
- target: {fileID: 6371086230447438899, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6869097019740516189, guid: f62bfcbfbc8097441a9fae9a02652a07,
type: 3}
propertyPath: m_Name
value: ClearCounter
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f62bfcbfbc8097441a9fae9a02652a07, type: 3}

View file

@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClearCounter : MonoBehaviour
{
public void Interact()
{
Debug.Log("Interacted!");
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bb159edc225081c408fe7a01d52732e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -7,12 +7,15 @@ public class Player : MonoBehaviour
[SerializeField] private float moveSpeed = 7f; [SerializeField] private float moveSpeed = 7f;
[SerializeField] private GameInput gameInput; [SerializeField] private GameInput gameInput;
[SerializeField] private LayerMask countersLayerMask;
private bool isWalking; private bool isWalking;
private Vector3 lastInteractDir;
private void Update() private void Update()
{ {
HandleMovement(); HandleMovement();
HandleInteractions();
} }
public bool IsWalking() public bool IsWalking()
@ -20,6 +23,36 @@ public class Player : MonoBehaviour
return isWalking; return isWalking;
} }
/// <summary>
/// Handle object interactions.
/// </summary>
private void HandleInteractions()
{
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
// Kepp a constantly updating record of the last move direction.
// This means you can interact without holding down a direction.
if (moveDir != Vector3.zero)
{
lastInteractDir = moveDir;
}
float interactDistance = 2f;
if (Physics.Raycast(transform.position, lastInteractDir, out RaycastHit raycastHit, interactDistance, countersLayerMask))
{
if (raycastHit.transform.TryGetComponent(out ClearCounter clearCounter))
{
// Has Clear Counter
clearCounter.Interact();
}
}
}
/// <summary>
/// Handle the player movement and collision.
/// </summary>
private void HandleMovement() private void HandleMovement()
{ {
Vector2 inputVector = gameInput.GetMovementVectorNormalized(); Vector2 inputVector = gameInput.GetMovementVectorNormalized();

View file

@ -11,7 +11,7 @@ TagManager:
- -
- Water - Water
- UI - UI
- - Counters
- -
- -
- -