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

unity 2d 入门 飞翔小鸟 死亡闪烁特效(十三)

一、c#脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Bling : MonoBehaviour
{public Texture img;public float speed;public static bool changeWhite = false;private float alpha=0f;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}private void OnGUI(){if (changeWhite) {alpha += speed * Time.deltaTime;if (alpha>=1) {changeWhite = false;}}else{if (alpha>0) {alpha -= speed * Time.deltaTime;}}GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha);GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),img);}public static void blinking(){changeWhite = true;}
}

二、在角色脚本触发物体脚本中引用闪烁脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Fly : MonoBehaviour
{//获取小鸟(刚体)private Rigidbody2D bird;//速度public float speed;//跳跃public float jump;//是否存活public static bool life = true;//获取动画器private Animator animator;// Start is called before the first frame updatevoid Start(){bird = GetComponent<Rigidbody2D>();animator = GetComponent<Animator>();}// Update is called once per framevoid Update(){//村换的时候才能运动if (life) { bird.velocity = new Vector2(speed, bird.velocity.y);//鼠标点击给目标一个纵向速度if (Input.GetMouseButtonDown(0)){bird.velocity = new Vector2(bird.velocity.x, jump);}}}//如果碰撞器撞到了某个物体private void OnCollisionEnter2D(Collision2D collision){if (life==true) {Bling.blinking();}life = false;animator.SetBool("life", false);}
}

在淡入淡出引用闪烁脚本

在这里插入图片描述

运行,触发物体就会闪烁

http://www.lryc.cn/news/259576.html

相关文章:

  • Cannot find cache named ‘‘ for Builder Redis
  • IntelliJ IDEA的下载安装配置步骤详解
  • 光线追踪算法实现
  • 学习深度强化学习---第3部分----RL蒙特卡罗相关算法
  • linux虚拟机使用81-persistent-net.rule后接口名依然改变的问题处理
  • ARMV8 - A64 - 跳转和返回指令
  • QX320F28335,自研内核指令集,主频150MHz,自研工具链,纯国产DSP,硬件兼容TMS320F28335
  • 《使用ThinkPHP6开发项目》 - 登录接口一
  • zabbix精简模板
  • GO设计模式——14、代理模式(结构型)
  • 外贸SOHO建站怎么做?海洋建站方法策略?
  • 商城免费搭建之java鸿鹄云商 java电子商务商城 Spring Cloud+Spring Boot+mybatis+MQ+VR全景+b2b2c
  • 【淘宝网消费类电子产品销售数据可视化】
  • AI编译器及TVM概述
  • 排序-归并排序与计数排序
  • 国产数据库适配-人大金仓(kingbase V8R3)
  • HAAS 哈斯机床 读写刀补数据
  • Visual studio+Qt开发环境搭建以及注意事项和打开qt的.pro项目
  • BUUCTF crypto做题记录(4)新手向
  • 【ArcGIS微课1000例】0080:ArcGIS将shp转json(geojson)案例教程
  • 阿里云Centos8安装Dockers详细过程
  • leetcode 二数之和 三数之和 四数之和
  • 制衣厂生产ERP系统怎么样?制衣厂生产ERP软件哪个好
  • 安装 DevEco Studio 后不能用本地 Node.js 打开
  • AppLink+WMS,实现仓储管理一体化
  • 如果是你,你选SOHO还是跟单?
  • 大语言模型--能力
  • 安装LLaMA-Factory微调chatglm3,修改自我认知
  • 以太网协议与DNS
  • Spring Boot的日志