Blood sucking start
This commit is contained in:
parent
755e6f4f0b
commit
0db69eab59
@ -12,6 +12,7 @@ GameObject:
|
||||
- component: {fileID: 1214567908930553592}
|
||||
- component: {fileID: 3126145803593047825}
|
||||
- component: {fileID: 1967503440015794769}
|
||||
- component: {fileID: 7967951869135974023}
|
||||
- component: {fileID: 1214567908930553595}
|
||||
- component: {fileID: 1214567908930553477}
|
||||
- component: {fileID: 945832017}
|
||||
@ -86,6 +87,20 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
minionPrefabs: []
|
||||
aimArrow: {fileID: 5124059627794595469}
|
||||
--- !u!114 &7967951869135974023
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1214567908930553593}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4bf4411b21939dd4780eef6579306f3d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
suckDuration: 1
|
||||
suckRange: 3
|
||||
--- !u!212 &1214567908930553595
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -207,7 +222,19 @@ MonoBehaviour:
|
||||
m_ActionId: eefb12f1-0980-4e79-a169-5b8d9c5f8909
|
||||
m_ActionName: Player/Jump[/XInputControllerWindows/buttonSouth,/Keyboard/space]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 7967951869135974023}
|
||||
m_TargetAssemblyTypeName: BloodSucker, Assembly-CSharp
|
||||
m_MethodName: ToggleSuck
|
||||
m_Mode: 0
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
m_ActionId: bd3662a8-0f8c-46c3-a035-be5ce123a673
|
||||
m_ActionName: Player/Suck[/XInputControllerWindows/buttonWest,/Keyboard/e]
|
||||
- m_PersistentCalls:
|
||||
|
||||
@ -132,7 +132,7 @@ PrefabInstance:
|
||||
m_Modifications:
|
||||
- target: {fileID: 3328484984159178892, guid: f7f5d2b1228d13f4d9015073aced3e81, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8365024801073869717, guid: f7f5d2b1228d13f4d9015073aced3e81, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
@ -220,7 +220,7 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8365024802335227869, guid: f7f5d2b1228d13f4d9015073aced3e81, type: 3}
|
||||
propertyPath: orthographic size
|
||||
value: 7
|
||||
value: 10
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: f7f5d2b1228d13f4d9015073aced3e81, type: 3}
|
||||
|
||||
90
Assets/Scripts/BloodSucker.cs
Normal file
90
Assets/Scripts/BloodSucker.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class BloodSucker : MonoBehaviour {
|
||||
|
||||
[SerializeField] float suckDuration = 1f;
|
||||
[SerializeField] float suckRange = 1f;
|
||||
|
||||
Entity currentTarget;
|
||||
VampireEntity vampireEntity;
|
||||
bool isSucking;
|
||||
float currentSuckTimer;
|
||||
|
||||
void Awake() {
|
||||
vampireEntity = GetComponent<VampireEntity>();
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
if (currentTarget == null) {
|
||||
SearchSuckTarget();
|
||||
}
|
||||
|
||||
if (currentTarget != null) {
|
||||
if (Vector3.Distance(currentTarget.transform.position, transform.position) > suckRange) {
|
||||
SetTarget(null);
|
||||
} else {
|
||||
if (isSucking) {
|
||||
PerformSuck(Time.fixedDeltaTime);
|
||||
// } else {
|
||||
// HighlightTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleSuck(InputAction.CallbackContext context) {
|
||||
if (context.performed) {
|
||||
if (currentTarget != null) {
|
||||
isSucking = true;
|
||||
currentSuckTimer = suckDuration;
|
||||
}
|
||||
} else if (context.canceled) {
|
||||
isSucking = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SearchSuckTarget() {
|
||||
foreach (Collider2D coll in Physics2D.OverlapCircleAll(transform.position, suckRange)) {
|
||||
Entity entity = coll.GetComponent<Entity>();
|
||||
if (entity != null && entity.gameObject != gameObject) {
|
||||
// TODO : check if target is dead
|
||||
SetTarget(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetTarget(Entity newTarget) {
|
||||
if (currentTarget != null) {
|
||||
UnHighlightTarget();
|
||||
}
|
||||
|
||||
currentTarget = newTarget;
|
||||
|
||||
if (currentTarget != null) {
|
||||
// print("new target : " + currentTarget.name);
|
||||
HighlightTarget();
|
||||
}
|
||||
}
|
||||
|
||||
void PerformSuck(float deltaTime) {
|
||||
currentSuckTimer -= deltaTime;
|
||||
if (currentSuckTimer < 0f) {
|
||||
// print("One token sucked");
|
||||
// TODO check if no token left
|
||||
SetTarget(null);
|
||||
isSucking = false;
|
||||
}
|
||||
}
|
||||
|
||||
void HighlightTarget() {
|
||||
|
||||
}
|
||||
|
||||
void UnHighlightTarget() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/BloodSucker.cs.meta
Normal file
11
Assets/Scripts/BloodSucker.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bf4411b21939dd4780eef6579306f3d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user