|
|
@@ -40,6 +40,11 @@ public class RockRoller : Enemy
|
|
|
public bool isBig;
|
|
|
private string enemyStr;
|
|
|
|
|
|
+ public GameObject stoneBreakEff;
|
|
|
+ public Transform effectSpawnPoint;
|
|
|
+ public float effectDestroyDelay = 2f;
|
|
|
+
|
|
|
+ public float smallStoneFoece = 20f;
|
|
|
public override void Init()
|
|
|
{
|
|
|
base.Init();
|
|
|
@@ -54,6 +59,7 @@ public class RockRoller : Enemy
|
|
|
InitializeStoneReference();
|
|
|
InitializeSpriter();
|
|
|
InitializeScale();
|
|
|
+ InitializeEffectSpawnPoint();
|
|
|
}
|
|
|
|
|
|
private void InitializeComponents()
|
|
|
@@ -108,6 +114,14 @@ public class RockRoller : Enemy
|
|
|
{
|
|
|
transform.localScale = new Vector3(1f, 1f, 1f)*scaleList[id];
|
|
|
}
|
|
|
+
|
|
|
+ private void InitializeEffectSpawnPoint()
|
|
|
+ {
|
|
|
+ if (effectSpawnPoint == null && stone != null)
|
|
|
+ {
|
|
|
+ effectSpawnPoint = stone.transform;
|
|
|
+ }
|
|
|
+ }
|
|
|
protected override void OnEnable()
|
|
|
{
|
|
|
base.OnEnable();
|
|
|
@@ -127,6 +141,7 @@ public class RockRoller : Enemy
|
|
|
isWeak = false;
|
|
|
rotateDirection = -1f;
|
|
|
curHitTime = 0;
|
|
|
+ stone.SetActive(true);
|
|
|
if (state == CharacterState.None)
|
|
|
{
|
|
|
ChangeState(CharacterState.Idle);
|
|
|
@@ -136,6 +151,7 @@ public class RockRoller : Enemy
|
|
|
if (attackTrigger0 != null)
|
|
|
attackTrigger0.gameObject.SetActive(true);
|
|
|
changeSpriter(0);
|
|
|
+ changeScale(0);
|
|
|
ResetTargetTypes();
|
|
|
}
|
|
|
|
|
|
@@ -155,6 +171,10 @@ public class RockRoller : Enemy
|
|
|
|
|
|
HandleOwnerSpecialState();
|
|
|
Rotate();
|
|
|
+ if (GameManager.instance.gameType == GameType.GameEnd)
|
|
|
+ {
|
|
|
+ ChangeState(CharacterState.Die);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Rotate()
|
|
|
@@ -171,7 +191,25 @@ public class RockRoller : Enemy
|
|
|
stone.transform.Rotate(Vector3.forward, rotateDirection * currentSpeed * Time.deltaTime);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ private void PlayBreakEff()
|
|
|
+ {
|
|
|
+ Vector3 spawnPos = effectSpawnPoint.position;
|
|
|
+ GameObject effectObj;
|
|
|
+ if (PoolManager.instance != null)
|
|
|
+ {
|
|
|
+ effectObj = PoolManager.Instantiate(stoneBreakEff, spawnPos);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ effectObj = Instantiate(stoneBreakEff, effectSpawnPoint);
|
|
|
+ }
|
|
|
+ effectObj.transform.localScale = transform.localScale;
|
|
|
+ // 自动销毁特效,防止内存泄漏
|
|
|
+ if (effectDestroyDelay > 0)
|
|
|
+ {
|
|
|
+ Destroy(effectObj, effectDestroyDelay);
|
|
|
+ }
|
|
|
+ }
|
|
|
private void UpdateHitFeedback()
|
|
|
{
|
|
|
hitFeedbackSystem.canBeHitStun = false;
|
|
|
@@ -210,6 +248,7 @@ public class RockRoller : Enemy
|
|
|
if (owner != null && owner.state == CharacterState.SpecialStatus_BlowUp &&
|
|
|
owner.attributeStatus.hitState == 1 && !isDying)
|
|
|
{
|
|
|
+ stone.SetActive(false);
|
|
|
StartDying();
|
|
|
}
|
|
|
|
|
|
@@ -238,6 +277,7 @@ public class RockRoller : Enemy
|
|
|
{
|
|
|
if (owner != null && curHitTime >= hitTime)
|
|
|
{
|
|
|
+ PlayBreakEff();
|
|
|
owner.gameObject.SetActive(false);
|
|
|
if (isBig)
|
|
|
{
|
|
|
@@ -257,16 +297,25 @@ public class RockRoller : Enemy
|
|
|
SingleEnemyConfig cfgEnemy = GameManager.instance.allCfgData.CfgEnemy.Get("小滚石怪");
|
|
|
|
|
|
// 生成第一个小石头
|
|
|
- GameObject enemyObj = Util.Instantiate(enemyStr, transform.position - new Vector3(-1, 0, 0), active: true);
|
|
|
- ConfigureSmallStone(enemyObj, cfgEnemy);
|
|
|
+ GameObject stone1 = Util.Instantiate(enemyStr, transform.position - new Vector3(0, 0, 0), active: true);
|
|
|
+ ConfigureSmallStone(stone1, cfgEnemy);
|
|
|
+ SmallStoneForce(stone1, new Vector3(-1, 1.2f, 0), smallStoneFoece);
|
|
|
|
|
|
// 生成第二个小石头
|
|
|
- GameObject enemyObj1 = Util.Instantiate(enemyStr, transform.position - new Vector3(1, 0, 0), active: true);
|
|
|
- ConfigureSmallStone(enemyObj1, cfgEnemy);
|
|
|
+ GameObject stone2 = Util.Instantiate(enemyStr, transform.position - new Vector3(0, 0, 0), active: true);
|
|
|
+ ConfigureSmallStone(stone2, cfgEnemy);
|
|
|
+ SmallStoneForce(stone2, new Vector3(1, 1.2f, 0), smallStoneFoece);
|
|
|
|
|
|
isFalled = false;
|
|
|
}
|
|
|
|
|
|
+ private void SmallStoneForce(GameObject stone, Vector3 forceDirection, float forceMul)
|
|
|
+ {
|
|
|
+ Rigidbody rockRb = stone.GetComponent<Rigidbody>();
|
|
|
+ RockRoller Roller = stone.GetComponent<RockRoller>();
|
|
|
+ Roller.ChangeState(CharacterState.Fall);
|
|
|
+ rockRb.AddForce(forceDirection * forceMul, ForceMode.Impulse);
|
|
|
+ }
|
|
|
private void ConfigureSmallStone(GameObject stoneObj, SingleEnemyConfig cfgEnemy)
|
|
|
{
|
|
|
RockRoller rock = stoneObj.GetComponent<RockRoller>();
|