
commit 9dbb855441c5b777bca9808280c8600e78e2363a Author: lspdC <961907320@qq.com> Date: Wed Apr 6 00:41:10 2022 +0800 4.5 简单UI动画 完成老虎boss战 场景切换会导致武器切换bug,排查中 commit f29c5c2a4cec3f062bdd6bbfd9bbb365188023d0 Author: lspdC <961907320@qq.com> Date: Sun Apr 3 01:45:27 2022 +0800 4.2(已合并) 合并分支 commit aed35a5f956c1f4cce30bd86cdb40bd0773d0322 Author: lspdC <961907320@qq.com> Date: Sun Apr 3 01:36:12 2022 +0800 4.2(未合并) 1、调整老虎动画,可以在简单的逻辑下连贯播放 2、修正开局没有武器会报错的bug,第一关倒下的树的树叶可以遮挡玩家。 commit 4383c04279f5a4270a3abe3b9f4cf67b4d133965 Author: lspdC <961907320@qq.com> Date: Fri Apr 1 23:35:01 2022 +0800 4.1(合并后) 整合摄像机等 commit 48e7207d351cfdb9363db27c0f8c1aba91fc05d9 Author: lspdC <961907320@qq.com> Date: Fri Apr 1 23:19:50 2022 +0800 4.1(未合并) commit 6154ddfbb4db880c270f650d090b47263e388cfd Author: lspdC <961907320@qq.com> Date: Thu Mar 31 00:17:09 2022 +0800 3.30 更新落雷动画,修复手持武器位置 明天整合摄像头并最后校对第一关场景和元素的大小比例 commit 28b3246896099b84afc84a05e39b581facfacce2 Author: lspdC <961907320@qq.com> Date: Mon Mar 28 11:24:23 2022 +0800 3.28(修改了京力酱场景内的player 不会报错) commit 399d8d91d968ef2e4538fc22acf2e5c9089f95cf Author: lspdC <961907320@qq.com> Date: Sun Mar 27 19:27:24 2022 +0800 3.27 整合了移动,受伤,与树、火交互的动画 物体绑定位置和部分动画衔接还有待进一步调整。 commit 76c1cf529eee651619a9542b85a90bdfe8d0bed1 Author: lspdC <961907320@qq.com> Date: Sat Mar 26 19:18:13 2022 +0800 3.26 下载美术动画素材 进一步整合中(预计还要整合一段时间,houdini还没做喵) commit 3771f6a9c19e37e50f62e5e054f2aefd94af9965 Author: lspdC <961907320@qq.com> Date: Fri Mar 25 23:39:57 2022 +0800 3.25 合并分支 commit c9c9ab412170ffd32a12b0660858625856aa3244 Author: lspdC <961907320@qq.com> Date: Thu Mar 24 22:11:29 2022 +0800 3.24 完成除boss战以外交互,逐步整合美术素材 commit 2a2a11e8514ab67008c85b25b6703888f1ed8824 Author: lspdC <961907320@qq.com> Date: Tue Mar 22 22:15:12 2022 +0800 3.22 完成了跟踪雷击与玩家的碰撞判定,玩家的受击反馈 击碎石头那边还有bug,明天再改 commit db3134349aaabb0ba0aaa64e43851ee0d6812fa0 Author: lspdC <961907320@qq.com> Date: Mon Mar 21 19:51:46 2022 +0800 3.21(和霄酱搅在一起了喵) commit d5836fec13668bd6a00ab8e9377f3959d86ab037 Author: lspdC <961907320@qq.com> Date: Mon Mar 21 19:49:15 2022 +0800 3.21(未合并) 完成火焰,碎石交互,武器升级替换。 设置好打雷演出框架,自动追击的雷击框架,尚未加入碰撞判定。 commit 698339a63c5ad608945a2e5702b7b216c97245c3 Author: lspdC <961907320@qq.com> Date: Sun Mar 20 23:28:11 2022 +0800 3.20 和京力交融之后的版本 commit 44c4946a717cd915dae1c92cb536031abf2f9343 Author: lspdC <961907320@qq.com> Date: Sun Mar 20 23:24:29 2022 +0800 3.20 整理了树木交互,写了个具体互动物品的基类。 创建了火类,实现火焰交互示意(拿上木棍才能成功交互)。 commit 1b5d15c2d2c98a71d12a79c9443d9cf4c89c7f40 Author: lspdC <961907320@qq.com> Date: Sun Mar 20 14:43:08 2022 +0800 sb coding # Conflicts: # Assets/Animate/Thunder/LightActing.anim # Assets/Animate/Tree/TreeByFrame.anim # Assets/Prefabs/着火.prefab # Assets/Prefabs/石刀.prefab # Assets/Prefabs/石斧.prefab # Assets/Prefabs/雷电将军.prefab # Assets/Scenes/乐/Sample1.unity # Assets/Scripts/乐/Fire.cs # Assets/Scripts/乐/Player.cs # Assets/Scripts/乐/Stone.cs # Assets/动画/cangjie 1.controller # Assets/动画/laohu.controller # Assets/动画/老虎冲撞.anim # Assets/动画/老虎前扑.anim # Assets/动画/老虎待机.anim # Assets/动画/老虎死亡.anim # Assets/动画/老虎走动.anim # Assets/预设/cangjie.prefab # Assets/预设/laohu.prefab # Logs/ApiUpdaterCheck.txt # UserSettings/EditorUserSettings.asset
314 lines
8.0 KiB
C#
314 lines
8.0 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.InputSystem;
|
||
using Sirenix.OdinInspector;
|
||
using DG.Tweening;
|
||
|
||
public class Player : PlayerControl
|
||
{
|
||
/// <summary>
|
||
/// 玩家刚体组件喵
|
||
/// </summary>
|
||
Rigidbody2D m_rigidbody;
|
||
|
||
[Header("骨骼")]
|
||
[FoldoutGroup("子物体")]
|
||
public GameObject bone;
|
||
Animator boneAnim;
|
||
|
||
/// <summary>
|
||
/// 脚底位置子物体
|
||
/// </summary>
|
||
[Header("脚底位置")] [FoldoutGroup("子物体")]
|
||
public Transform groundCheck;
|
||
|
||
/// <summary>
|
||
/// 手持武器
|
||
/// </summary>
|
||
[ReadOnly]
|
||
[Header("手持武器")] [FoldoutGroup("子物体")]
|
||
public Item weapon;
|
||
|
||
/// <summary>
|
||
/// 武器生成位置(需要绑在骨骼上)
|
||
/// </summary>
|
||
|
||
[Header("武器生成位置(需要绑在骨骼上)")]
|
||
[FoldoutGroup("子物体")]
|
||
public Transform weaponTrans;
|
||
[Header("武器生成位置偏移")]
|
||
[FoldoutGroup("子物体")]
|
||
public Vector3 weaponPos;
|
||
|
||
/// <summary>
|
||
/// 角色朝向(向右为1)
|
||
/// </summary>
|
||
[ReadOnly] [Header("朝向监测")]
|
||
public int isRight = 1;
|
||
|
||
/// <summary>
|
||
/// 角色是否落地
|
||
/// </summary>
|
||
[ReadOnly]
|
||
[Header("落地监测")]
|
||
public bool isGround = false;
|
||
|
||
|
||
|
||
[Header("行走速度")][FoldoutGroup("角色操作数据")]
|
||
public float speed;
|
||
|
||
[Header("跳跃力量")][FoldoutGroup("角色操作数据")]
|
||
public float jumpForce;
|
||
|
||
|
||
/// <summary>
|
||
/// 角色翻面时长
|
||
/// </summary>
|
||
[Header("角色翻面所需时长")]
|
||
public float flipDuration = 0.1f;
|
||
|
||
|
||
|
||
//布尔-------------------------
|
||
bool forceFlip = false;
|
||
bool isHurting = false;
|
||
|
||
|
||
/// <summary>
|
||
/// 玩家初始化喵
|
||
/// </summary>
|
||
override protected void Start()
|
||
{
|
||
base.Start();
|
||
m_rigidbody = gameObject.GetComponent<Rigidbody2D>();
|
||
boneAnim = bone.gameObject.GetComponent<Animator>();
|
||
//WeaponInit();
|
||
}
|
||
|
||
//UPDATE
|
||
void Update()
|
||
{
|
||
//Debug.Log(weapon.name + " " + weapon.GetIsAtk());
|
||
|
||
//OnInputDetect();
|
||
Flip();
|
||
|
||
/*
|
||
if (inputDir!=0 && boneAnim.GetBool("Move")==false)
|
||
boneAnim.SetBool("Move", true);
|
||
*/
|
||
}
|
||
|
||
void FixedUpdate() {
|
||
Moving();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 翻面函数
|
||
/// </summary>
|
||
void Flip()
|
||
{
|
||
int lastFrameDir = isRight;
|
||
if (inputDir * lastFrameDir < 0 || forceFlip == true)
|
||
{ isRight *= -1;
|
||
//transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
|
||
//transform.DOScale(new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z),0.1f);
|
||
|
||
//分情况定值翻转 可以规避在旋转动画未结束时再次翻转的造成的起始角度不同从而影响目标角度误差的问题
|
||
switch (isRight) {
|
||
case 1:
|
||
transform.DORotate(new Vector3(0, 0, 0), flipDuration);
|
||
break;
|
||
case -1:
|
||
transform.DORotate(new Vector3(0,180,0), flipDuration);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
/*
|
||
/// <summary>
|
||
/// 检测是否停止摇杆输入
|
||
/// </summary>
|
||
void OnInputDetect() {
|
||
if (inputDir == 0&&isHurting==false)
|
||
Freeze();
|
||
}*/
|
||
|
||
/// <summary>
|
||
/// 强制静止
|
||
/// </summary>
|
||
void Freeze() {
|
||
m_rigidbody.velocity = new Vector2(0,m_rigidbody.velocity.y);
|
||
}
|
||
|
||
void Moving() {
|
||
if (isHurting == false)
|
||
{
|
||
switch (inputDir) {
|
||
case 0:
|
||
boneAnim.SetBool("Move",false);
|
||
break;
|
||
default:
|
||
boneAnim.SetBool("Move",true);
|
||
break;
|
||
}
|
||
|
||
m_rigidbody.velocity = new Vector2(inputDir * speed, m_rigidbody.velocity.y); }
|
||
|
||
else
|
||
boneAnim.SetBool("Move", false);
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <param name="ctx"></param>
|
||
override protected void OnMove(InputAction.CallbackContext ctx)
|
||
{
|
||
base.OnMove(ctx);
|
||
|
||
}
|
||
override protected void OnAtk() {
|
||
base.OnAtk();
|
||
AtkAnim();
|
||
weapon.SetIsAtk(true);
|
||
StopInput(1.2f);
|
||
|
||
|
||
}
|
||
override protected void OnJump() {
|
||
base.OnJump();
|
||
if (isGround == true) {
|
||
isGround = false;
|
||
m_rigidbody.velocity = new Vector2(m_rigidbody.velocity.x, jumpForce);
|
||
}
|
||
|
||
}
|
||
override protected void OnInteract() {
|
||
base.OnInteract();
|
||
|
||
}
|
||
|
||
protected override void OnLeftChange()
|
||
{
|
||
ItemController.Instance.LeftChangeItem();
|
||
}
|
||
|
||
protected override void OnRightChange()
|
||
{
|
||
//WeaponReturn();
|
||
ItemController.Instance.RightChangeItem();
|
||
//WeaponInPosition();
|
||
}
|
||
|
||
//武器更换相关函数--------------------------------------------------
|
||
public void WeaponInPosition() {
|
||
GameObject chosenOne;
|
||
try
|
||
{
|
||
chosenOne = GameObject.Find(weapon.name);
|
||
if (chosenOne.TryGetComponent<Item>(out Item chosenWeapen))
|
||
chosenWeapen.InPosition(weaponTrans, weaponPos);
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
e.ToString();
|
||
Debug.LogError("初始武器未绑定,若本关卡需要武器,请绑定,否则无视此信息" );
|
||
}
|
||
|
||
}
|
||
|
||
public void WeaponReturn()
|
||
{
|
||
GameObject chosenOne;
|
||
chosenOne = GameObject.Find(weapon.name);
|
||
if (chosenOne.TryGetComponent<Item>(out Item chosenWeapon))
|
||
{
|
||
//Debug.Log(chosenOne.name + chosenWeapon.GetOriposition());
|
||
chosenWeapon.ReturnToOri(); }
|
||
|
||
}
|
||
//武器生成---------------------------------------------------------
|
||
void WeaponInit() {
|
||
WeaponInPosition();
|
||
}
|
||
|
||
//受到攻击
|
||
public void GetHurt(int count,float time,float hitter_x) {
|
||
isHurting = true;
|
||
StopInput(time);
|
||
//播动画
|
||
HurtInteractAnim();
|
||
if ((hitter_x - transform.position.x)*isRight< 0) {
|
||
forceFlip = true;
|
||
Flip();
|
||
forceFlip = false;
|
||
}
|
||
m_rigidbody.velocity = new Vector2(-isRight * 3, 3);
|
||
|
||
}
|
||
|
||
public void StopInput(float time) {
|
||
ToMap("Null");
|
||
Invoke(nameof(ResetInput), time);
|
||
|
||
}
|
||
|
||
void ResetInput() {
|
||
ToMap("Normal");
|
||
isHurting = false;
|
||
weapon.SetIsAtk(false);
|
||
}
|
||
|
||
//跳跃判定(有点怪 后面可能会改)
|
||
|
||
private void OnCollisionEnter2D(Collision2D collision)//当有物体碰上
|
||
{
|
||
//创到地面时触发一次
|
||
if (collision.transform.CompareTag("Ground"))
|
||
{
|
||
//向脚底发射一条短射线
|
||
Ray2D ray = new Ray2D(
|
||
groundCheck.position,
|
||
Vector2.down
|
||
);
|
||
Debug.DrawRay(ray.origin, ray.direction, Color.red, 10f);
|
||
//获取射线的碰撞结果
|
||
RaycastHit2D hit2D;
|
||
hit2D = Physics2D.Raycast(ray.origin, ray.direction, 0.001f);
|
||
//如果射线有结果并且射线创到的是地面,才表示着地了
|
||
if (hit2D && hit2D.collider.transform.CompareTag("Ground"))
|
||
{
|
||
isGround = true;
|
||
}
|
||
else Debug.Log("Not Ground");
|
||
}
|
||
}
|
||
|
||
|
||
//-----------------------------------动画控制-----------------------------------
|
||
|
||
public void TreeInteractAnim() {
|
||
boneAnim.SetTrigger("与树交互");
|
||
}
|
||
public void FireInteractAnim()
|
||
{
|
||
boneAnim.SetTrigger("与火交互");
|
||
}
|
||
public void HurtInteractAnim() {
|
||
boneAnim.SetTrigger("受伤");
|
||
}
|
||
|
||
public void StoneInteractAnim()
|
||
{
|
||
boneAnim.SetTrigger("与火交互");
|
||
}
|
||
|
||
public void AtkAnim() {
|
||
boneAnim.SetTrigger("攻击");
|
||
}
|
||
}
|