Colliding with certain obj can stun the player
This commit is contained in:
parent
babbc78b4f
commit
b9777f7a62
29
Assets/PlayerController.cs
Normal file
29
Assets/PlayerController.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private LayerMask stunLayerMask;
|
||||
private GrappleHook grappleScript;
|
||||
[SerializeField]
|
||||
private float stunDuration;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
grappleScript = GetComponent<GrappleHook>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other) {
|
||||
if(((1<<other.gameObject.layer) & stunLayerMask) != 0){//Collided w/ somtehing that stuns
|
||||
grappleScript.Stun(stunDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/PlayerController.cs.meta
Normal file
11
Assets/PlayerController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b5fa9960655cb742880ef94db81ca9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -542,7 +542,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 335131023}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 16.07, y: 10.1, z: 0}
|
||||
m_LocalPosition: {x: 9.4, y: 16.4, z: 0}
|
||||
m_LocalScale: {x: 2.8042, y: 2.8042, z: 6.9}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@ -1444,6 +1444,12 @@ 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
|
||||
@ -1456,7 +1462,7 @@ GameObject:
|
||||
- component: {fileID: 952326955}
|
||||
- component: {fileID: 952326954}
|
||||
- component: {fileID: 952326953}
|
||||
m_Layer: 3
|
||||
m_Layer: 7
|
||||
m_Name: Floor_02
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
@ -2023,6 +2029,22 @@ 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
|
||||
|
||||
@ -39,11 +39,11 @@ public class GrappleHook : MonoBehaviour
|
||||
private SpringJoint joint;
|
||||
private LineRenderer lr;
|
||||
RaycastHit hit;
|
||||
private bool grappled = false, grappling = false, boosted = false, changingLength = false;
|
||||
private bool grappled = false, grappling = false, boosted = false, changingLength = false, isStunned = false;
|
||||
float changingLengthDir = 0;
|
||||
private Vector3 currGrappleEndPos;
|
||||
|
||||
|
||||
#region private methods
|
||||
void Start()
|
||||
{
|
||||
lr = gameObject.GetComponentInChildren<LineRenderer>();
|
||||
@ -55,6 +55,9 @@ public class GrappleHook : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(isStunned){
|
||||
return;
|
||||
}
|
||||
|
||||
if(grappled){
|
||||
DrawRope(Time.deltaTime);
|
||||
@ -153,6 +156,23 @@ public class GrappleHook : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
private void UnStun(){
|
||||
isStunned = false;
|
||||
Debug.Log("unstunned");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public methods
|
||||
|
||||
public void Stun(float duration){
|
||||
isStunned = true;
|
||||
EndGrapple();
|
||||
Debug.Log("Stunned");
|
||||
Invoke("UnStun", duration);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region InputActions
|
||||
public void Grapple(InputAction.CallbackContext context){
|
||||
if(grappling && grappled)return;
|
||||
if(context.performed){
|
||||
@ -194,5 +214,5 @@ public class GrappleHook : MonoBehaviour
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ TagManager:
|
||||
- Water
|
||||
- UI
|
||||
- Grappleable
|
||||
-
|
||||
- Stun
|
||||
-
|
||||
-
|
||||
-
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user