2024-10-21 10:08:49 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public enum CharacterState
|
|
|
|
|
{
|
|
|
|
|
idle,
|
|
|
|
|
SlowWalk,
|
|
|
|
|
walk,
|
|
|
|
|
run,
|
|
|
|
|
jump,
|
2024-10-21 17:21:28 +08:00
|
|
|
|
Dead,
|
2024-10-21 18:09:07 +08:00
|
|
|
|
|
2024-10-21 10:08:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum CharacterSkill
|
|
|
|
|
{
|
|
|
|
|
NoSkill,//0
|
|
|
|
|
Watering, //1
|
2024-10-21 18:09:07 +08:00
|
|
|
|
jump,//2
|
2024-10-23 20:48:23 +08:00
|
|
|
|
Rescue,//3
|
|
|
|
|
OperateSuccess,//4
|
|
|
|
|
OperateFail//5
|
2024-10-21 10:08:49 +08:00
|
|
|
|
}
|
2024-10-22 11:57:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-21 10:08:49 +08:00
|
|
|
|
public class CharacterAin : MonoBehaviour
|
|
|
|
|
{
|
2024-12-02 15:09:22 +08:00
|
|
|
|
[Header("<22><><EFBFBD><EFBFBD>")]
|
|
|
|
|
public Animator ain;
|
2024-10-21 10:08:49 +08:00
|
|
|
|
private float timer;
|
|
|
|
|
private float RunSpeed;
|
|
|
|
|
|
2024-12-02 15:09:22 +08:00
|
|
|
|
[HideInInspector]
|
|
|
|
|
public CharacterState characterState;
|
2024-10-21 10:08:49 +08:00
|
|
|
|
|
2024-12-02 15:09:22 +08:00
|
|
|
|
[Header("<22><>ײ<EFBFBD><D7B2>")]
|
|
|
|
|
public Collider PlayerCollider;
|
2024-10-21 10:08:49 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
|
|
|
|
private Vector3 colExtents;
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
ReState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
|
{
|
2024-12-02 15:09:22 +08:00
|
|
|
|
//ain = transform.GetComponent<Animator>();
|
|
|
|
|
colExtents = PlayerCollider.bounds.extents;
|
2024-10-21 10:08:49 +08:00
|
|
|
|
characterState = CharacterState.idle;
|
|
|
|
|
SetPlayerState(characterState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>Ķ<EFBFBD><C4B6><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="characterState">״̬ö<CCAC><C3B6></param>
|
|
|
|
|
public void SetPlayerState(CharacterState characterState)
|
|
|
|
|
{
|
|
|
|
|
if (this.characterState == CharacterState.Dead)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.characterState = characterState;
|
|
|
|
|
RunSpeed = ain.GetFloat("RunSpeed");
|
|
|
|
|
|
|
|
|
|
switch (this.characterState)
|
|
|
|
|
{
|
|
|
|
|
case CharacterState.idle:
|
|
|
|
|
ain.SetInteger("State", 0);
|
|
|
|
|
ain.SetFloat("RunSpeed", Mathf.Lerp(RunSpeed, 0f, 0.1f)); // <20><><EFBFBD><EFBFBD> Lerp <20>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ֵϵ<D6B5><CFB5>
|
|
|
|
|
ain.SetBool("IsOnGround", true);
|
|
|
|
|
break;
|
|
|
|
|
case CharacterState.SlowWalk:
|
|
|
|
|
ain.SetInteger("State", 1);
|
|
|
|
|
ain.SetFloat("RunSpeed", Mathf.Lerp(RunSpeed, 0.4f, 0.1f)); // <20><>С<EFBFBD><D0A1><EFBFBD>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
case CharacterState.walk:
|
|
|
|
|
ain.SetInteger("State", 1);
|
|
|
|
|
ain.SetFloat("RunSpeed", Mathf.Lerp(RunSpeed, 0.6f, 0.1f)); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
case CharacterState.run:
|
|
|
|
|
ain.SetInteger("State", 1);
|
|
|
|
|
ain.SetFloat("RunSpeed", Mathf.Lerp(RunSpeed, 2f, 0.1f)); // <20>ܲ<EFBFBD><DCB2>ٶ<EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
case CharacterState.jump:
|
|
|
|
|
ain.SetBool("IsOnGround", false);
|
|
|
|
|
ain.SetInteger("State", 2);
|
|
|
|
|
break;
|
|
|
|
|
case CharacterState.Dead:
|
|
|
|
|
ain.SetInteger("State", 99);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ﵱǰ״̬
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public CharacterState GetCharacterState()
|
|
|
|
|
{
|
|
|
|
|
return this.characterState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBC>⣬<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ڵ<EFBFBD><DAB5><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool IsOnGround()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Ray ray = new Ray(this.transform.position + Vector3.up * (2 * colExtents.x), Vector3.down);
|
|
|
|
|
|
|
|
|
|
if (Physics.SphereCast(ray, colExtents.x, colExtents.x + 0.2f))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>棬<EFBFBD>ָ<EFBFBD>վ<EFBFBD><D5BE>
|
|
|
|
|
public void ReState()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (characterState == CharacterState.jump && IsOnGround())
|
|
|
|
|
{
|
|
|
|
|
SetPlayerState(CharacterState.idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD>ܶ<EFBFBD><DCB6><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Skill"></param>
|
|
|
|
|
public void SetSkillAin(CharacterSkill Skill)
|
|
|
|
|
{
|
|
|
|
|
switch (Skill)
|
|
|
|
|
{
|
|
|
|
|
case CharacterSkill.NoSkill:
|
|
|
|
|
ain.SetInteger("Skill", 0);
|
|
|
|
|
break;
|
|
|
|
|
case CharacterSkill.Watering:
|
|
|
|
|
ain.SetInteger("Skill", 1);
|
|
|
|
|
break;
|
|
|
|
|
case CharacterSkill.jump:
|
|
|
|
|
ain.SetInteger("Skill", 2);
|
|
|
|
|
break;
|
2024-10-21 18:09:07 +08:00
|
|
|
|
case CharacterSkill.Rescue:
|
|
|
|
|
ain.SetInteger("Skill",3);
|
|
|
|
|
break;
|
2024-10-23 20:48:23 +08:00
|
|
|
|
case CharacterSkill.OperateSuccess:
|
|
|
|
|
ain.SetInteger("Skill", 4);
|
|
|
|
|
break;
|
|
|
|
|
case CharacterSkill.OperateFail:
|
|
|
|
|
ain.SetInteger("Skill", 5);
|
|
|
|
|
break;
|
2024-10-21 10:08:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-22 11:57:50 +08:00
|
|
|
|
IEnumerator jiutimer(float timer)
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSeconds(timer);
|
|
|
|
|
}
|
2024-10-21 10:08:49 +08:00
|
|
|
|
|
|
|
|
|
}
|