import { _decorator, Component, Node, Sprite, UITransform, Vec3 } from 'cc'; const { ccclass, property } = _decorator; @ccclass('hp_bar') export class hp_bar extends Component { @property(Node) point:Node = null @property(Node) hp_bar:Node = null private total:number = 100 public init(){ } public updateHp(hp:number){ let range = (hp/this.total) this.hp_bar.getComponent(Sprite).fillRange = range let heigth = this.hp_bar.getComponent(UITransform).contentSize.height this.point.position = new Vec3(this.point.position.x,heigth*(range>1?1:range)) } }