当前位置: 首页 > wzjs >正文

个人未授权做的网站网站seo站长工具

个人未授权做的网站,网站seo站长工具,电商seo与sem是什么,推广一次多少钱创建一个2d正方形(9-Sliced)命名为Player,在Player下面新建一个画布(Canvas)命名为PlayerHealthUI,在画布下面新建一个滑动条(Slider)命名为HealthBar 把PlayerHealthUI脚本挂载到Pl…

创建一个2d正方形(9-Sliced)命名为Player,在Player下面新建一个画布(Canvas)命名为PlayerHealthUI,在画布下面新建一个滑动条(Slider)命名为HealthBar

把PlayerHealthUI脚本挂载到PlayerHealthUI上,拖拽情况如图所示

using UnityEngine;
using UnityEngine.UI;public class PlayerHealthUI : MonoBehaviour
{[SerializeField] private Slider healthBar;[SerializeField] private Health health;//更新血条方法(注意要写成公有的)public void UpdateUI(){healthBar.value = health.Value;}//进入游戏的时候开启private void Awake(){//起始值:血条UI的起始值=health的初始值healthBar.maxValue = health.Value;//更新:血条UI的现在值=health的初始值healthBar.value = health.Value;}
}

把playerMovement脚本,Health脚本,Damageable脚本,挂载到Player对象上,拖拽情况如图所示

using UnityEngine;
using UnityEngine.InputSystem;
using DG.Tweening;public class playerMovement : MonoBehaviour
{[SerializeField]private Rigidbody2D rb;private Vector2 _inputDirection;[SerializeField]private float _speed;public void Move(InputAction.CallbackContext context){_inputDirection = context.ReadValue<Vector2>();}private void FixedUpdate(){var position = (Vector2)transform.position;var targetPosition = position + _inputDirection;if (position == targetPosition) return;rb.DOMove(targetPosition, _speed).SetSpeedBased();}
}

using UnityEngine;
using UnityEngine.Events;public class Health : MonoBehaviour
{[SerializeField] private int health;[SerializeField] private UnityEvent<int> healthchange;public int Value{get { return health; }}//减少血量public void DreaseHealth(int amount){//血量减去被传进来的值health -= amount;healthchange.Invoke(health);}}

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Damageable : MonoBehaviour
{[SerializeField]private Health health;//想要实现被伤害时变红闪烁一下[SerializeField]private SpriteRenderer spriteRenderer;public void TakeDamage(int damage){health.DreaseHealth(damage);//在DG.Tweening包中,记得引入//DOColor()需要的两个arguement:第一个是确定颜色,第二个是完成变换所需要的时间//再变回去需要SetLoops(),两个arguemengt,一个是变换几圈,一个是以什么方式变//红色到白色是一圈,红色到白色是另一圈//Yoyo:慢慢变换//还需要用ChangeStartValue()给一个起始颜色spriteRenderer.DOColor(Color.red,0.2f).SetLoops(2,LoopType.Yoyo).ChangeStartValue(Color.white);}
}

把Attack脚本和EnemyMovement脚本,挂载到Enemy对象上

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class EnemyMovement : MonoBehaviour
{[SerializeField] private Rigidbody2D rb;[SerializeField] private float _speed;[SerializeField]private PlayerManager playerManager;private void FixedUpdate(){//玩家当前位置var playPosition = playerManager.position;//敌人自己当前位置坐标var position=(Vector2)transform.position;//当前距离距玩家位置(移动的方向)var direction=playPosition-position; //数字规范(方便计算)direction.Normalize();//目的坐标var targetPosition = position + direction;//向目的地移动rb.DOMove(targetPosition, _speed).SetSpeedBased();}}

using UnityEngine;
using Timers;public class Attack : MonoBehaviour
{private bool _canAttack = true;private void OnTriggerEnter2D(Collider2D col){DealDamage(col);}private void OnTriggerStay2D(Collider2D other){DealDamage(other);}private void CanAttack(){_canAttack=true;}private void DealDamage(Collider2D other){if (!_canAttack) return;//Player为标签if (other.CompareTag("Player")){var damageable = other.GetComponent<Damageable>();damageable.TakeDamage(10);//三个argumentTimersManager.SetTimer(this, 1, CanAttack);_canAttack = false;}}
}
PlayerManager脚本挂载到空物体Manager上面
using UnityEngine;//获取玩家位置
public class PlayerManager:MonoBehaviour
{[SerializeField] private Transform playerTransform;//任何脚本呼叫PlayerManager时,都可以获得玩家位置public Vector2 position{get { return playerTransform.position; }}
}

http://www.dtcms.com/wzjs/234726.html

相关文章:

  • 做网站汉中学软件开发学费多少钱
  • 做土特产网站什么名字最好西安网站设计开发
  • 线上运营推广好处在于某企业网站的分析优化与推广
  • 网站管理员中心专业百度seo排名优化
  • 建设网站所采用的技术方案seo关键词优化培训班
  • 顺企网上海网站建设黄页推广2021
  • 网站开发流程asp什么是seo搜索优化
  • 制作网站结构设计百度关键字搜索排名
  • 网站风格有哪些怎么制作网站平台
  • 手机网站域名开头百度竞价软件哪个好
  • 做婚姻网站流程抖音关键词排名系统
  • 做网站 包含详情页设计吗百度推广官网登录
  • 公司简历模板表格石家庄百度快照优化排名
  • 网站制作用什么软件百度推广怎么弄
  • 网站开发的母的目的和意义.网店推广的作用
  • 济南专业做网站的公司哪家好拓客平台有哪些
  • 企业网站建设目的选择题百度竞价排名名词解释
  • 工业部网站备案网站域名怎么注册
  • 营销型企业网站源码首页排名优化公司
  • 新疆建设人才培训网网站关键词优化方法
  • 做的网站手机打不开怎么回事啊磁力链搜索引擎入口
  • 北京品牌网站建设公司排名营销型网站建设报价
  • 上海市政府网站建设与对策分析山东seo费用多少
  • 英文网站 常用字体提高seo排名
  • 廊坊关键词seo排名网站公众号软文推广
  • 建筑工程行业网站建设方案什么推广平台好
  • 聊城做网站哪家好公司建官网要多少钱
  • 视频网站中滑动列表怎么做的百度官网认证免费
  • 网站搭建教学网网站广告制作
  • 政府类网站建设淘宝app官方下载