任务:搭建基本的系统

1.编写伊斯兰小怪逻辑
(1.继承于Enemy类
(2.初始化时直接为Seek状态
(3.每帧执行Seek函数,让其水平方向有冲向玩家的速度
(4.当触发Touch玩家事件,伊斯兰触发协程Boom
(*.给伊斯兰类添加触发器监听,当玩家进入触发器范围,标记可以炸到玩家;当玩家离开触发器,标记无法炸到玩家
(5.当Boom执行时,标记自身为dead,关闭自身碰撞体,抄一下NormalEnemy的被击飞函数,并使刚体开始旋转。同时判定玩家是否可被炸到,若能,击飞玩家并造成相对的伤害值。
(6.从NormalEnemy代码复制过来了受击逻辑
*:整理伊斯兰代码

至此,伊斯兰小怪的逻辑基本开发完毕

*修复攻击时能够转身的问题

2.编写屏幕和手柄震动相关逻辑
(1.设计震动类
(2.设计静态方法ShakeScream和ShakePad,其中ShakePad为协程,调用时请使用StartContinue。

3.为玩家起跳添加屏幕晃动和手柄震动
This commit is contained in:
Roman 2021-12-05 00:40:50 +08:00
parent 032bef564e
commit 7d2c965521
12 changed files with 652 additions and 24 deletions

View File

@ -12,7 +12,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c46f07b5ed07e4e92aa78254188d3d10, type: 3}
m_Name: InputSystem.inputsettings
m_EditorClassIdentifier:
m_SupportedDevices: []
m_SupportedDevices:
- Gamepad
- Keyboard
m_UpdateMode: 1
m_CompensateForScreenOrientation: 1
m_FilterNoiseOnCurrent: 0

8
Assets/RawSignal.meta Normal file
View File

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

View File

@ -0,0 +1,28 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b7f59e54f2bfd184b9dd451a678d089b, type: 3}
m_Name: "\u9707\u52A8\u7BA1\u7406\u5458 Raw Signal"
m_EditorClassIdentifier:
PositionNoise:
- X:
Frequency: 0
Amplitude: 0
Constant: 0
Y:
Frequency: 6
Amplitude: 1
Constant: 1
Z:
Frequency: 0
Amplitude: 0
Constant: 0
OrientationNoise: []

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: be080484924830741a80f3039f48e82b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -429,7 +429,7 @@ MonoBehaviour:
targetGO: {fileID: 0}
tweenTargetIsTargetGO: 1
delay: 0
duration: 0.25
duration: 0.5
easeType: 1
easeCurve:
serializedVersion: 2
@ -571,7 +571,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 326335321}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 9.45, y: 0.153, z: 0}
m_LocalPosition: {x: 4.24, y: 0.153, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 321454206}
@ -879,7 +879,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 10.219999, y: 0.953, z: -10}
m_LocalPosition: {x: 5.0099998, y: 0.953, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 189736997}
@ -920,6 +920,188 @@ MonoBehaviour:
m_CameraActivatedEvent:
m_PersistentCalls:
m_Calls: []
--- !u!1 &574826834
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 574826839}
- component: {fileID: 574826838}
- component: {fileID: 574826837}
- component: {fileID: 574826836}
- component: {fileID: 574826835}
- component: {fileID: 574826840}
m_Layer: 0
m_Name: "\u4F0A\u65AF\u5170"
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &574826835
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574826834}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3b862b4b8276d94ab3dfb01ab55e5dd, type: 3}
m_Name:
m_EditorClassIdentifier:
HP: 1
ATK: 1
speed: 3
coin: 5
canBeHit: 1
HPLeft: 0
state: 0
deadRotationRangeMax: 500
deadRotationRangeMin: 500
boomTime: 0
hitToflyParameter: {x: 3, y: 3}
--- !u!61 &574826836
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574826834}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
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: 0.56, y: 1.08}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.56, y: 1.08}
m_EdgeRadius: 0
--- !u!61 &574826837
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574826834}
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: 0.56, y: 1.08}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.56, y: 1.08}
m_EdgeRadius: 0
--- !u!212 &574826838
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574826834}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 6ab25cc35002c7e49a620e5c373a83c8, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 1
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!4 &574826839
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574826834}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 8.33, y: 0.37, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &574826840
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574826834}
m_BodyType: 0
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: 0
m_Constraints: 0
--- !u!1 &659041640
GameObject:
m_ObjectHideFlags: 0
@ -1379,6 +1561,7 @@ GameObject:
m_Component:
- component: {fileID: 1160673896}
- component: {fileID: 1160673895}
- component: {fileID: 1160673897}
m_Layer: 0
m_Name: CM vcam1
m_TagString: Untagged
@ -1429,13 +1612,28 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1160673894}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 10.219999, y: 0.953, z: -10}
m_LocalPosition: {x: 5.0099998, y: 0.953, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1225561446}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1160673897
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1160673894}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 00b2d199b96b516448144ab30fb26aed, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ChannelMask: 1
m_Gain: 1
m_Use2DDistance: 1
--- !u!1 &1225561445
GameObject:
m_ObjectHideFlags: 3
@ -2024,6 +2222,128 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!1 &1820087957
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1820087959}
- component: {fileID: 1820087958}
- component: {fileID: 1820087960}
m_Layer: 0
m_Name: "\u9707\u52A8\u7BA1\u7406\u5458"
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1820087958
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1820087957}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 180ecf9b41d478f468eb3e9083753217, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ImpulseDefinition:
m_ImpulseChannel: 1
m_RawSignal: {fileID: 11400000, guid: be080484924830741a80f3039f48e82b, type: 2}
m_AmplitudeGain: 1
m_FrequencyGain: 1
m_RepeatMode: 0
m_Randomize: 1
m_TimeEnvelope:
m_AttackShape:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 1
inSlope: 0.0057156202
outSlope: 0.0057156202
tangentMode: 0
weightedMode: 0
inWeight: 0.6298815
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
m_DecayShape:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 0
inSlope: -0.008401664
outSlope: -0.008401664
tangentMode: 0
weightedMode: 0
inWeight: 0.38794905
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
m_AttackTime: 0.1
m_SustainTime: 0.1
m_DecayTime: 0.1
m_ScaleWithImpact: 1
m_HoldForever: 0
m_ImpactRadius: 100
m_DirectionMode: 0
m_DissipationMode: 2
m_DissipationDistance: 1000
m_PropagationSpeed: 343
--- !u!4 &1820087959
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1820087957}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.8626485, y: 0.5469756, z: -2.6886199}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1820087960
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1820087957}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8552cc6ae4e3ee6439c72af8eff091ff, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2098309882
GameObject:
m_ObjectHideFlags: 0
@ -2115,7 +2435,7 @@ BoxCollider2D:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2098309882}
m_Enabled: 1
m_Enabled: 0
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1

View File

@ -46,6 +46,7 @@ public class Enemy : MonoBehaviour
/// <summary>
/// 此时怪物能否被攻击
/// </summary>
[FoldoutGroup("状态")][Header("当前是否能被攻击")][ReadOnly]
public bool canBeHit = true;
// _____ _ _
@ -132,12 +133,9 @@ public class Enemy : MonoBehaviour
else if(other.gameObject.tag == "地面")
{OnRetouchedTheGround();}
}
protected void OnTriggerEnter2D(Collider2D other)
protected virtual void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.TryGetComponent<MyPlayer>(out MyPlayer player))
{OnFindThePlayer(other.transform);}//如果监视范围出现玩家则Call事件
}
}

View File

@ -5,15 +5,6 @@ using UnityEngine.InputSystem;
using DG.Tweening;
using Sirenix.OdinInspector;
// _
// | |
// _ __ | | __ _ _ _ ___ _ __
// | '_ \| |/ _` | | | |/ _ \ '__|
// | |_) | | (_| | |_| | __/ |
// | .__/|_|\__,_|\__, |\___|_|
// | | __/ |
// |_| |___/
/// <summary>
/// 玩家类,控制玩家相关的东西
/// </summary>
@ -177,6 +168,9 @@ public class MyPlayer : MonoBehaviour
if(sickleCDLeft > 0) sickleCDLeft -= Time.deltaTime;
}
/// <summary>
/// 转身的时候触发
/// </summary>
private void TurnAround()
{
faceDir = inputDir;
@ -229,7 +223,7 @@ public class MyPlayer : MonoBehaviour
private void CatchingHarm(){
HPLeft -= FindObjectOfType<AiYuPin>().ATK;
}
//碰撞检测代码
// _____ _ _ _ _
// / ____| | | (_) (_)
// | | ___ | | |_ ___ _ ___ _ __
@ -265,7 +259,7 @@ public class MyPlayer : MonoBehaviour
else inputDir = 0;
if(faceDir * inputDir < 0){
if(inControl)TurnAround();
if(inControl && !isAttacking)TurnAround();
if(isCatching){catingAiYuPin.OnBreakFree();}
}
}
@ -281,7 +275,9 @@ public class MyPlayer : MonoBehaviour
jumpForce);//垂直方向给予预设跳跃速度
//标记自身正在跳跃
isJumping = true;
}
VibrationManager.ShakeScream(Vector2.up,0.5f);
StartCoroutine(VibrationManager.ShakePad(0.1f,0.2f,0.2f));
}
}
}
@ -348,7 +344,13 @@ public class MyPlayer : MonoBehaviour
/// <summary>
/// 锤子攻击动画结尾Event调用
/// </summary>
public void StopAttacking(){isAttacking = false;}
public void StopAttacking(){isAttacking = false;
//解决面部朝向的问题
if(faceDir * inputDir < 0){
if(inControl && !isAttacking)TurnAround();
if(isCatching){catingAiYuPin.OnBreakFree();}
}
}
/// <summary>
/// 当玩家被爱欲品抓住后触发这个事件

View File

@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using Sirenix.OdinInspector;
using UnityEngine.InputSystem;
/// <summary>
/// 震动管理员,管理相机和手柄的震动,外部调用静态方法
/// </summary>
public class VibrationManager : MonoBehaviour
{
/// <summary>
/// 震动相机,仅对于一些微小短小震动使用
/// </summary>
/// <param name="dir">震动方向</param>
/// <param name="force">震动力度</param>
public static void ShakeScream(Vector2 dir,float force){
FindObjectOfType<CinemachineImpulseSource>().
GenerateImpulse(dir * force);
}
/// <summary>
/// 震动手柄
/// </summary>
/// <param name="left">左马达力度(低频)</param>
/// <param name="right">右马达力度(高频)</param>
/// <param name="time">震动时间</param>
public static IEnumerator ShakePad(float left, float right, float time){
if(Gamepad.current != null){
Gamepad.current.SetMotorSpeeds(left,right);
yield return new WaitForSeconds(time);
Gamepad.current.SetMotorSpeeds(0,0);
}
}
}

View File

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

167
Assets/Scripts/YiSiLan.cs Normal file
View File

@ -0,0 +1,167 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
/// <summary>
/// 伊斯兰小怪类
/// </summary>
public class YiSiLan : Enemy
{
// _____ _ _ _
// | __ \ | | | (_)
// | |__) | _| |__ | |_ ___
// | ___/ | | | '_ \| | |/ __|
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
[FoldoutGroup("其他",false,0)][Header("怪物死后旋转速度的随机区间")]
public float deadRotationRangeMax;
[FoldoutGroup("其他",false,0)]
public float deadRotationRangeMin;
/// <summary>
/// 抓到玩家后多长事件触发爆炸
/// </summary>
[Header("抓到玩家后多长事件触发爆炸")][FoldoutGroup("伊斯兰")]
public float boomTime;
/// <summary>
/// 被击飞力度的调整值
/// </summary>
[Header("被攻击后击飞的力度调整值")][FoldoutGroup("其他",false,0)]
public Vector2 hitToflyParameter;
// _____ _ _
// | __ \ (_) | |
// | |__) | __ ___ ____ _| |_ ___
// | ___/ '__| \ \ / / _` | __/ _ \
// | | | | | |\ V / (_| | || __/
// |_| |_| |_| \_/ \__,_|\__\___|
private Rigidbody2D m_rigidbody;
/// <summary>
/// seek函数中的追踪目标
/// </summary>
private Transform target;
/// <summary>
/// 记录此时玩家是否在爆炸范围内
/// </summary>
private bool canHitPlayer;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
// | | __ _| | | |_) | __ _ ___| | __
// | | / _` | | | _ < / _` |/ __| |/ /
// | |___| (_| | | | |_) | (_| | (__| <
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
void Start(){Init();}//初始化
void FixedUpdate(){if(state == State.seek)Seek();}//seek
// _ _ _
// | \ | | | |
// | \| | ___ _ __ _ __ ___ __ _| |
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
// | |\ | (_) | | | | | | | | (_| | |
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
private void Init(){
//初始化状态为Seek
state = State.seek;
//找到必要的组件
m_rigidbody = GetComponent<Rigidbody2D>();
target = FindObjectOfType<MyPlayer>().transform;
}
/// <summary>
/// 寻找函数每Fixed调用
/// </summary>
private void Seek(){
//构造一个方向1代表向右-1代表向左
int dir = (target.position.x - transform.position.x > 0) ? 1:-1;
//使刚体水平方向上获得速度
m_rigidbody.velocity = new Vector2(speed * dir,
m_rigidbody.velocity.y);
//矫正一下faceDir的问题,使其始终朝向玩家
transform.rotation = Quaternion.
Euler
(transform.rotation.x,
((dir == 1) ? 0:-180),
transform.rotation.z);
}
/// <summary>
/// 伊斯兰爆炸的时候Call这个通过协程触发因为爆炸有个延时
/// </summary>
private void Boom(){
OnDead();
if(canHitPlayer){
FindObjectOfType<MyPlayer>().OnBeHit(ATK,(target.position.x - transform.position.x > 0) ? -1:1);
//加一个扭矩,营造死亡的效果
m_rigidbody.AddTorque(Random.Range(deadRotationRangeMin,deadRotationRangeMax) *
((target.position.x - transform.position.x > 0) ? -1:1));
}
}
/// <summary>
/// 被击飞的击飞效果处理
/// </summary>
/// <param name="dir">被击方向</param>
public void BeHitToFly(int dir){
m_rigidbody.velocity += new Vector2( //给予自身一个
-1 * dir * hitToflyParameter.x,//X方向为力度系数乘以受击方向
hitToflyParameter.y//Y方向为力度系数
//的绝对的速度
);
}
/// <summary>
/// 协程用,删除自己这个游戏物体
/// </summary>
protected void Dead(){Destroy(gameObject);}
// ______ _
// | ____| | |
// | |____ _____ _ __ | |_
// | __\ \ / / _ \ '_ \| __|
// | |___\ V / __/ | | | |_
// |______\_/ \___|_| |_|\__|
protected override void OnTouchThePlayer(MyPlayer player){Invoke("Boom",boomTime);}
protected override void OnDead(){
//标记当前状态为死亡
state = State.dead;
//加一个扭矩,营造死亡的效果
m_rigidbody.AddTorque(Random.Range(deadRotationRangeMin,deadRotationRangeMax) *
((target.position.x - transform.position.x > 0) ? -1 : 1));
//关掉自己的碰撞体
GetComponent<BoxCollider2D>().enabled = false;
//两秒后自己毁灭
Invoke("Dead",2f);
}
public override void OnBeHit(MyPlayer.AtkMethod hitMethod, int hitDir){
//让自己被击飞
BeHitToFly(hitDir);
//结算生命值
HPLeft -= MyPlayer.atkMethodMagnification[hitMethod];
//看下死了没
//死了就记录下死亡时候的面部朝向用来做死亡翻滚效果然后再Call一下死亡事件
if(CheckDead()) {OnDead();}
//被打飞了在着地前都不会挨打了
canBeHit = false;
}
// _____ _ _ _ _
// / ____| | | (_) (_)
// | | ___ | | |_ ___ _ ___ _ __
// | | / _ \| | | / __| |/ _ \| '_ \
// | |___| (_) | | | \__ \ | (_) | | | |
// \_____\___/|_|_|_|___/_|\___/|_| |_|
//触发器代表炸弹范围,进入说明能炸到,离开说明炸不到了
protected override void OnTriggerEnter2D(Collider2D other){
base.OnTriggerEnter2D(other);
canHitPlayer = true;
}
void OnTriggerExit2D(Collider2D other){canHitPlayer = false;}
}

View File

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

View File

@ -46,7 +46,7 @@ TextureImporter:
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spritePixelsToUnits: 200
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
@ -75,6 +75,42 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []