Moved stun logic to obj instead of player
This commit is contained in:
parent
b9777f7a62
commit
fd9cee838c
@ -16,9 +16,10 @@ GameObject:
|
||||
- component: {fileID: 1772573266731274173}
|
||||
- component: {fileID: 1772573266731274172}
|
||||
- component: {fileID: 1772573266731274163}
|
||||
- component: {fileID: 8474203461765366282}
|
||||
m_Layer: 0
|
||||
m_Name: Player
|
||||
m_TagString: Untagged
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
@ -293,6 +294,18 @@ MonoBehaviour:
|
||||
playerHeight: 0.5
|
||||
isGrounded: 0
|
||||
isJumping: 0
|
||||
--- !u!114 &8474203461765366282
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1772573266731274171}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9b5fa9960655cb742880ef94db81ca9c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1772573266864950258
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -1444,12 +1444,6 @@ MonoBehaviour:
|
||||
m_ShadowLayerMask: 1
|
||||
m_LightCookieSize: {x: 1, y: 1}
|
||||
m_LightCookieOffset: {x: 0, y: 0}
|
||||
--- !u!1 &951718810 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 1772573266731274171, guid: 4dbf735f9da7b9f43b69f1577e4e5763,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 1341139406}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &952326952
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -1462,7 +1456,8 @@ GameObject:
|
||||
- component: {fileID: 952326955}
|
||||
- component: {fileID: 952326954}
|
||||
- component: {fileID: 952326953}
|
||||
m_Layer: 7
|
||||
- component: {fileID: 952326957}
|
||||
m_Layer: 3
|
||||
m_Name: Floor_02
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
@ -1547,6 +1542,19 @@ Transform:
|
||||
m_Father: {fileID: 778227310}
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &952326957
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 952326952}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3a94b6c0021fca74ba1778a83054fbe8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
duration: 1
|
||||
--- !u!1 &1070079036
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -2029,22 +2037,6 @@ Transform:
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 1341139406}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &1341139415
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 951718810}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9b5fa9960655cb742880ef94db81ca9c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
stunLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 128
|
||||
stunDuration: 2
|
||||
--- !u!1 &1530935835
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -21,12 +21,15 @@ public class CharacterMovement : MonoBehaviour
|
||||
[SerializeField] private float playerHeight;
|
||||
public bool isGrounded;
|
||||
public bool isJumping;
|
||||
|
||||
private bool isStunned = false;
|
||||
|
||||
private Vector3 rawInputMovement;
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if(isStunned){
|
||||
return;
|
||||
}
|
||||
if (canWalk || canJump)
|
||||
{
|
||||
|
||||
@ -62,6 +65,14 @@ public class CharacterMovement : MonoBehaviour
|
||||
rb.drag= airDrag;
|
||||
}
|
||||
|
||||
public void Stun(float duration){
|
||||
isStunned = true;
|
||||
Invoke("Unstun" ,duration);
|
||||
}
|
||||
private void Unstun(){
|
||||
isStunned = false;
|
||||
}
|
||||
|
||||
public void Walk(InputAction.CallbackContext value){
|
||||
|
||||
if (canWalk)
|
||||
|
||||
@ -124,6 +124,7 @@ public class GrappleHook : MonoBehaviour
|
||||
Rigidbody hitRb = hit.rigidbody;
|
||||
joint.connectedBody = hitRb;
|
||||
joint.connectedAnchor = hit.transform.InverseTransformPoint(hit.point);
|
||||
joint.enableCollision = true;
|
||||
hitPosLocal = hit.transform.InverseTransformPoint(hit.point);
|
||||
}else{
|
||||
joint.connectedAnchor = hit.point;
|
||||
|
||||
@ -4,15 +4,13 @@ using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private LayerMask stunLayerMask;
|
||||
private GrappleHook grappleScript;
|
||||
[SerializeField]
|
||||
private float stunDuration;
|
||||
private CharacterMovement movementScript;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
grappleScript = GetComponent<GrappleHook>();
|
||||
movementScript = GetComponent<CharacterMovement>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@ -21,9 +19,8 @@ public class PlayerController : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other) {
|
||||
if(((1<<other.gameObject.layer) & stunLayerMask) != 0){//Collided w/ somtehing that stuns
|
||||
grappleScript.Stun(stunDuration);
|
||||
}
|
||||
public void Stun(float duration){
|
||||
grappleScript.Stun(duration);
|
||||
movementScript.Stun(duration);
|
||||
}
|
||||
}
|
||||
15
Assets/Scripts/Stunning.cs
Normal file
15
Assets/Scripts/Stunning.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Stunning : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float duration;
|
||||
|
||||
private void OnCollisionEnter(Collision other) {
|
||||
if(other.gameObject.tag.Equals("Player")){//Collided w/ player, stun him
|
||||
other.gameObject.GetComponent<PlayerController>().Stun(duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Stunning.cs.meta
Normal file
11
Assets/Scripts/Stunning.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a94b6c0021fca74ba1778a83054fbe8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user