COCOS 3.7 播放UI动画及跨脚本通信(小白记录)

本文介绍了两个UnityCC脚本,一个是buttonanim,它在游戏对象加载时设置动画并在按钮被点击时播放特定的动画片段。另一个是showview,用于监听场景中的特定事件并在事件触发时改变节点的活跃状态。
摘要由CSDN通过智能技术生成

 脚本A

import { _decorator, Component, Node, Animation,AnimationClip, director } from 'cc';
const { ccclass, property } = _decorator;



@ccclass('buttonanim')
export class buttonanim extends Component {

    @property(Animation)//创建一个节点,属性是animation
    kkk: Animation = null;//节点名为KKK

    @property(Node)
    public viewoffon: Node = null;


    onLoad() {
      
    }
    start() {
        this.kkk.play("animation");//挂载到物体后播放动画片段
  
    }

    onbuttonclicked() {

        director.getScene().emit('showkkkkk');//向当前场景发出通知

    }

    update(deltaTime: number) {
        
    }
}


 脚本B

import { _decorator, Component, Node, director } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('showview')
export class showview extends Component {
    @property(Node) //创建一个节点node类型
    abdd: Node = null;

    onLoad() {
       
    }

    start() {
        //this.node.active = false;
        director.getScene().on('showkkkkk', this.onbtnclick, this);//监听此场景内的通知,回调给onbtnclick
    }

    update(deltaTime: number) {
        
    }

    onbtnclick() {
        this.node.active = false;//执行操作
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我救我自己

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值