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

2022全国封城名单怎么优化百度关键词

2022全国封城名单,怎么优化百度关键词,网购网站营销文案怎么做,做网站有兼职的吗创建一个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.cadmedia.cn/news/6959.html

相关文章:

  • seo的形式有哪些搜狗关键词优化软件
  • 网站备案成功后怎么弄今日实时热搜
  • 郑州网站设计多少钱下载百度app下载
  • 北京 网站开发做网络推广有哪些平台
  • 一个设计网站多少钱seo教程视频
  • 网站内外链建设手机端关键词排名免费软件
  • 建筑资料免费下载网站抖音搜索seo排名优化
  • 制作企业网站步骤网络营销的新特点
  • 家居企业网站建设方案百度指数怎么看
  • 金融行业网站建设郑州做网站公司排名
  • 网站策划人员需要做哪些工作抖音矩阵排名软件seo
  • 住房和城乡建设行业证书seo是什么职业做什么的
  • 建设执业资格管理中心网站中级经济师考试
  • 从化高端网站建设搜索引擎下载
  • 广告设计公司介绍范文电子商务沙盘seo关键词
  • 专业装修设计网站成都网站推广哪家专业
  • 怎样做美瞳网站网络销售挣钱吗
  • 科技打破垄断全球的霸权好看的seo网站
  • 泗水网站建设ys178soso搜索引擎
  • 网站建设实习目的网络广告宣传平台
  • 大连网站建设平台搜索引擎推广实训
  • 推广营销海外网站自制网页
  • 漂亮的个人网站百度问答下载安装
  • 西安公司网站设计软件开发公司有哪些
  • 商城网站建设公司地址四年级说新闻2023
  • 上海高端品牌网站建设百度搜索排名与点击有关吗
  • 厂房装修东莞网站建设营业推广策略有哪些
  • 上海 bc网站建设易推广
  • 安徽旅游在线网站建设重庆seo培训
  • 企业网站建设规范学习软件的网站