Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

把Label组件作为预制资源,怎么改变它的string?

$
0
0

@Daguidwn 写道:

这些代码没报错,但无法改变Label组件的string,请问问题出在哪里?

properties: {
    ScorePrefab : {
        default : null,
        type : cc.Prefab,
    },
},

onLoad: function () {
    var ScoreLabel = cc.instantiate(this.ScorePrefab);
    this.node.addChild(ScoreLabel);
    ScoreLabel.setPosition(0,0);
    this.ScoreLabel = ScoreLabel;
    window.Score = 0;
},

update: function () {
    if(...) {
        window.Score += 1;
        this.ScoreLabel.string = 'Score: ' + window.Score.toString();
    }
},

感觉像是这一行写错了this.ScoreLabel.string = 'Score: ' + window.Score.toString();
请问正确的代码写法是什么?

帖子: 4

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>