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

超市网站建设方案模板织梦新闻门户网站模板

超市网站建设方案模板,织梦新闻门户网站模板,网站后台发邮件,seo的宗旨是什么创建一个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/783200.html

相关文章:

  • app和手机网站的区别站长工具域名解析
  • 网站建设推广和网络推广易语言可以做网站嘛
  • 网站 备案 中国 名字吗wordpress 亲子模板下载
  • 陕西哪些公司做企业网站张槎建网站
  • 网站 需求电子商务网站建设的必要性
  • 网站设计与网页设计的区别企业网络推广软件
  • 怎么样建立个人网站没有公司做网站
  • 杂志在线设计网站wordpress 免费中文模板下载
  • 石家庄建设局官方网站比wordpress更好的网站程序
  • 哪个地方网站建设的公司多上海做网站开发的公司有哪些
  • 网站前端开发框架中山市建设信息网站
  • 扁平化网站布局win没有wordpress
  • 域名已有服务器也有怎么做网站经典设计产品
  • 怎样给公司做一个网站电商网站订烟
  • 机械网站怎么做百度信息流
  • 整站优化系统厂家手机在线图片编辑器
  • 网站搜索 收录优化设计师网络用语
  • 学校做安全台账是哪个网站wordpress底部排
  • 新零售网站建设网页游戏排行榜前
  • 福永附近做网站公司莱州网站建设报价
  • 陕西网站维护北京到安阳火车时刻表查询
  • 建设网站美海房地产提供设计的网站
  • 出国做网站工作手机做的兼职网站
  • 怎样在工商局网站上做变更如何策划网络事件营销
  • 站长工具seo综合查询外部链接数量廊坊网站建设联系青橙网络
  • 攸县住房和城乡规划建设局网站python在线编程视频
  • 建设企业网站价钱河北建设网
  • 做电商网站用什么技术通过手机建设网站
  • 多个网站集成在一个页面网站新闻页面设计
  • html制作静态网站模板网站登记表