|
|
@@ -17,7 +17,8 @@ public enum PlayerState
|
|
|
Hurt = 5,
|
|
|
Attack = 6,
|
|
|
Summon = 7,
|
|
|
- Die = 8,
|
|
|
+ Rush = 8,
|
|
|
+ Die = 9,
|
|
|
}
|
|
|
public class PlayerController : MonoBehaviour
|
|
|
{
|
|
|
@@ -40,6 +41,7 @@ public class PlayerController : MonoBehaviour
|
|
|
public float maxMoveSpeed = 5;
|
|
|
//public float moveAcc = 5f;
|
|
|
//public float airMoveAcc = 3f;
|
|
|
+ public float rushSpeed = 100;
|
|
|
|
|
|
public PlayerState state = PlayerState.Idle;
|
|
|
[HideInInspector]
|
|
|
@@ -68,6 +70,12 @@ public class PlayerController : MonoBehaviour
|
|
|
public float totalCacheSummonTime = 0.1f;
|
|
|
[HideInInspector]
|
|
|
public int cacheSummonId;
|
|
|
+ [HideInInspector]
|
|
|
+ public float rushTime;
|
|
|
+ public float totalRushTime = 0.5f;
|
|
|
+ [HideInInspector]
|
|
|
+ public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
|
|
|
+ public float totalCacheRushTime = 0.1f;
|
|
|
|
|
|
public bool isDie = false;
|
|
|
|
|
|
@@ -79,6 +87,14 @@ public class PlayerController : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
public bool isClickBtnJump;
|
|
|
+ public bool btnRushPress
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public bool isClickBtnRush;
|
|
|
public bool btnSouthPress
|
|
|
{
|
|
|
get
|
|
|
@@ -130,6 +146,10 @@ public class PlayerController : MonoBehaviour
|
|
|
|
|
|
private void Update()
|
|
|
{
|
|
|
+ if (Input.GetKeyDown(KeyCode.LeftShift))
|
|
|
+ {
|
|
|
+ isClickBtnRush = true;
|
|
|
+ }
|
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
|
{
|
|
|
isClickBtnJump = true;
|
|
|
@@ -201,6 +221,8 @@ public class PlayerController : MonoBehaviour
|
|
|
hurtKeepTime -= Time.deltaTime;
|
|
|
attackTime -= Time.deltaTime;
|
|
|
summonTime -= Time.deltaTime;
|
|
|
+ rushTime -= Time.deltaTime;
|
|
|
+ cacheRushTime -= Time.deltaTime;
|
|
|
switch (state)
|
|
|
{
|
|
|
case PlayerState.Idle:
|
|
|
@@ -229,6 +251,11 @@ public class PlayerController : MonoBehaviour
|
|
|
Summon(cacheSummonId);
|
|
|
break;
|
|
|
}
|
|
|
+ if (btnRushPress || cacheRushTime > 0)
|
|
|
+ {
|
|
|
+ ChangeState(PlayerState.Rush);
|
|
|
+ break;
|
|
|
+ }
|
|
|
if (btnJumpPress || cacheJumpTime > 0)
|
|
|
{
|
|
|
Jump();
|
|
|
@@ -282,6 +309,11 @@ public class PlayerController : MonoBehaviour
|
|
|
Summon(cacheSummonId);
|
|
|
break;
|
|
|
}
|
|
|
+ if (btnRushPress || cacheRushTime > 0)
|
|
|
+ {
|
|
|
+ ChangeState(PlayerState.Rush);
|
|
|
+ break;
|
|
|
+ }
|
|
|
if (btnJumpPress || cacheJumpTime > 0)
|
|
|
{
|
|
|
Jump();
|
|
|
@@ -334,6 +366,11 @@ public class PlayerController : MonoBehaviour
|
|
|
}
|
|
|
break;
|
|
|
case PlayerState.Rise:
|
|
|
+ if (btnRushPress || cacheRushTime > 0)
|
|
|
+ {
|
|
|
+ ChangeState(PlayerState.Rush);
|
|
|
+ break;
|
|
|
+ }
|
|
|
if (rb.velocity.y <= 0)
|
|
|
{
|
|
|
ChangeState(PlayerState.Fall);
|
|
|
@@ -348,6 +385,10 @@ public class PlayerController : MonoBehaviour
|
|
|
// break;
|
|
|
// }
|
|
|
//}
|
|
|
+ if (btnRushPress)
|
|
|
+ {
|
|
|
+ cacheRushTime = totalCacheRushTime;
|
|
|
+ }
|
|
|
if (btnJumpPress)
|
|
|
{
|
|
|
cacheJumpTime = totalCacheJumpTime;
|
|
|
@@ -375,6 +416,11 @@ public class PlayerController : MonoBehaviour
|
|
|
AirMove();
|
|
|
break;
|
|
|
case PlayerState.Fall:
|
|
|
+ if (btnRushPress || cacheRushTime > 0)
|
|
|
+ {
|
|
|
+ ChangeState(PlayerState.Rush);
|
|
|
+ break;
|
|
|
+ }
|
|
|
if (foot.TrigGround)
|
|
|
{
|
|
|
ChangeState(PlayerState.Idle);
|
|
|
@@ -406,6 +452,10 @@ public class PlayerController : MonoBehaviour
|
|
|
// break;
|
|
|
// }
|
|
|
//}
|
|
|
+ if (btnRushPress)
|
|
|
+ {
|
|
|
+ cacheRushTime = totalCacheRushTime;
|
|
|
+ }
|
|
|
if (btnJumpPress)
|
|
|
{
|
|
|
cacheJumpTime = totalCacheJumpTime;
|
|
|
@@ -438,6 +488,10 @@ public class PlayerController : MonoBehaviour
|
|
|
ChangeState(PlayerState.Idle);
|
|
|
break;
|
|
|
}
|
|
|
+ if (btnRushPress)
|
|
|
+ {
|
|
|
+ cacheRushTime = totalCacheRushTime;
|
|
|
+ }
|
|
|
if (btnJumpPress)
|
|
|
{
|
|
|
cacheJumpTime = totalCacheJumpTime;
|
|
|
@@ -473,6 +527,10 @@ public class PlayerController : MonoBehaviour
|
|
|
ChangeState(PlayerState.Idle);
|
|
|
break;
|
|
|
}
|
|
|
+ if (btnRushPress)
|
|
|
+ {
|
|
|
+ cacheRushTime = totalCacheRushTime;
|
|
|
+ }
|
|
|
if (btnJumpPress)
|
|
|
{
|
|
|
cacheJumpTime = totalCacheJumpTime;
|
|
|
@@ -503,6 +561,10 @@ public class PlayerController : MonoBehaviour
|
|
|
ChangeState(PlayerState.Idle);
|
|
|
break;
|
|
|
}
|
|
|
+ if (btnRushPress)
|
|
|
+ {
|
|
|
+ cacheRushTime = totalCacheRushTime;
|
|
|
+ }
|
|
|
if (btnJumpPress)
|
|
|
{
|
|
|
cacheJumpTime = totalCacheJumpTime;
|
|
|
@@ -527,9 +589,25 @@ public class PlayerController : MonoBehaviour
|
|
|
cacheSummonId = 2;
|
|
|
}
|
|
|
break;
|
|
|
+ case PlayerState.Rush:
|
|
|
+ if (rushTime <= 0)
|
|
|
+ {
|
|
|
+ ChangeState(PlayerState.Idle);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (transform.localScale.x > 0)
|
|
|
+ {
|
|
|
+ rb.velocity = Vector3.left * rushSpeed;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rb.velocity = Vector3.right * rushSpeed;
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+ isClickBtnRush = false;
|
|
|
isClickBtnJump = false;
|
|
|
isClickBtnSouth = false;
|
|
|
isClickBtnEast = false;
|
|
|
@@ -553,6 +631,10 @@ public class PlayerController : MonoBehaviour
|
|
|
break;
|
|
|
case PlayerState.Attack:
|
|
|
break;
|
|
|
+ case PlayerState.Summon:
|
|
|
+ break;
|
|
|
+ case PlayerState.Rush:
|
|
|
+ break;
|
|
|
case PlayerState.Die:
|
|
|
isDie = false;
|
|
|
break;
|
|
|
@@ -614,6 +696,12 @@ public class PlayerController : MonoBehaviour
|
|
|
ani.Play("summon", 0, 0);
|
|
|
summonTime = totalSummonTime;
|
|
|
break;
|
|
|
+ case PlayerState.Rush:
|
|
|
+ bodyCollider.enabled = true;
|
|
|
+ jumpBodyCollider.enabled = false;
|
|
|
+ ani.Play("rush_loop", 0, 0);
|
|
|
+ rushTime = totalRushTime;
|
|
|
+ break;
|
|
|
case PlayerState.Die:
|
|
|
bodyCollider.enabled = false;
|
|
|
jumpBodyCollider.enabled = false;
|