if和else块中的语句为何都执行了?

onLoad: function () { var anim = this.getComponent(cc.Animation); if(anim !== null) { anim.play('clip'); console.log('anim不为空'); } else { console.log('anim为空'); } },
然后我打开控制台发现anim不为空和anim为空这两句话都输出了,表示if和else里的语句有执行了,这是为什么呢?

打个断点看一下不就清楚了?

找到问题了,我不小心把这个脚本挂在两个结点上了

有点走进科学的感觉

这个标题容易被打

能出现这种问题的 一般都和引擎无关了 都是自己搞出来的问题