import { _decorator , Component , Sprite , Material } from 'cc' ; const { ccclass , property , executeInEditMode } = _decorator ; @ ccclass ( 'Flash' ) @ executeInEditMode export default class Flash extends Component { img : Sprite | null = null ; material : Material | undefined | null = null ; startTime : number = Date . now ( ) ; time : number = 0 ; onLoad ( ) { this . img = this . getComponent ( Sprite ) ; this . material = this . img ?. sharedMaterial ; } update ( ) { this . time = ( Date . now ( ) - this . startTime ) / 1000 ; this . material ?. setProperty ( "time" , this . time ) ; } }