脚本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;//执行操作
}
}