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

cocos shader敌人受到攻击改变颜色

在这里插入图片描述
视频 [视频](https://www.bilibili.com/video/BV1SMpXzTErd/?
https://www.bilibili.com/video/BV1SMpXzTErd/?vd_source=fcaf9af78115af41b55fe1f11da57759vd_source=fcaf9af78115af41b55fe1f11da57759)
将前面的shader简单改下
取消根据dist画光柱 还是判断图片是否透明
o.rgb = original.rgb + glowEffect ;这个取消
换成glowcolor.rgb 用选择的颜色称为受到攻击后变得颜色
然后价格脚本 子弹碰撞后再敌人node下shouji脚本有个将material中shader uniform变量切换的
在shader中写了glowspread超过0会将图片本色换成受到攻击颜色
在脚本中发生碰撞后将0超过1
然后再0.4秒后回到1
otherCollider.node.getComponent(direnshouji).direnshouji();
子弹碰撞后调用othercollider中的敌人node下的脚本

onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact |null){//console.log("ziji",selfCollider.node.name);//console.log("zhuang",otherCollider.node.name);const guaiwu=otherCollider.node;this.showlizi(selfCollider.node.position);guaiwu.getComponent(enemyhit).shoushang(this.danfahit);const bullet=selfCollider.node;if (bullet && bullet.isValid) {// 先从数组中移除const index = this.fashezidansz.indexOf(bullet);if (this.bulletsToRemove.indexOf(bullet) === -1) {this.bulletsToRemove.push(bullet);}let xue=otherCollider.node.getComponent(enemyhit).getxue();otherCollider.node.getComponent(direnshouji).direnshouji();if(xue<=0){//console.log('huan',this.guai.name);}// 标记需要销毁的子弹,而不是立即销毁// 然后回收子弹}
import { _decorator, Component, Node, Sprite } from 'cc';
const { ccclass, property } = _decorator;@ccclass('direnshouji')
export class direnshouji extends Component {q:number=0;qo:number=0;qoo:number=0;start() {}update(deltaTime: number) {}
direnshouji(){const me=this.node.getComponent(Sprite);this.q=(this.q+0.1)%19;this.qoo=(this.qoo+0.001)%0.2;const time = Date.now();this.qo=(this.qo+0.1)%1;//console.log(this.q);me.material.setProperty('glowSpread',this.qo);this.qo=0;this.scheduleOnce(()=>{me.material.setProperty('glowSpread',this.qo);},0.4);
}
}
vec4 frag () {vec4 o =  texture(cc_spriteTexture,uv);vec4 original=o;// 固定光柱宽度和移动速度float beamPos = mod(glowSpread -0.3, 3.0) ;float dist = abs(uv.x - beamPos);//if(dist < glowIntensity) { // 固定光柱宽度为0.1if(o.a>0.0){
// 计算光柱强度 (中心最强,边缘最弱)float strength = 1.0 - dist / glow;// 从白色渐变到 glowColorvec3 glowEffect = mix(vec3(1.0), glowColor.rgb, uv.x / glowIntensity);// 应用发光效果if(glowSpread>0.0){o.rgb=glowColor.rgb;//o.rgb = original.rgb + glowEffect ;//o.a = max(original.a, strength);}}//}return o;}
http://www.dtcms.com/a/393306.html

相关文章:

  • cd论文精读
  • USBD_malloc 禁止替换成 malloc 函数
  • 功能测试与测试用例设计方法详解
  • AXI DMA
  • 1:1复刻真实场景,机器人训练不再“纸上谈兵”
  • CMake快速上手:编译、构建与变量管理(包含示例)
  • vscode配置C/C++教程(含常见问题)
  • F021 五种推荐算法之美食外卖推荐可视化系统vue+flask
  • C++学习记录(10)模板进阶
  • cesium案例:三维钢铁厂园区开发平台(附源码下载)
  • 电商开放平台API接口对比爬虫的优势有哪些?
  • SpringDoc-OpenApi 现代化 API 文档生成工具介绍+使用
  • 打造现象级H5答题游戏:《终极主题答题冒险》开源项目详解
  • 实验1.2呼吸灯实验指导书
  • 实验1.3通过for循环精确定时呼吸灯
  • 【c++】多态(一)
  • 01、Python从入门到癫狂:基础
  • uniapp 弹窗
  • 17.2 《16小时→2.3小时!多模态AI颠覆PPT制作:跨国企业实战验证》
  • MyBatis 从入门到实战:环境搭建与核心原理详解
  • 深入剖析陌讯AIGC检测算法:Transformer架构在AIGC识别中的技术创新
  • 【Ai智能客服上篇】
  • 《C++程序设计》笔记p3
  • 华为数字化转型战略框架:从“1套方法+4类场景+3个平台”的全景设计
  • Redis:主从复制与哨兵模式解析
  • 【中压选型篇】中压电源进线与变压器选型全指南:从拓扑设计到并联运行
  • 【精品资料鉴赏】数据治理咨询项目实施方案
  • 基于陌讯AIGC检测算法的局限性探讨:最大512Token输入下的长文本处理方案
  • 应用随机过程(三)
  • A/B测试:随机化与观察单位不一致,如何处理更科学