import { _decorator, Component, Label, Node, RigidBody } from 'cc'; const { ccclass, property } = _decorator; export enum Cube_State { live, wait, dead } @ccclass('Cube_Infor') export class Cube_Infor extends Component { @property(Label) txt: Label; @property(Label) txt2: Label; @property(RigidBody) rigidbody: RigidBody; text: string; state: Cube_State = Cube_State.live; // 添加缓存状态来避免重复切换 isUp:boolean=false; start() { } update(deltaTime: number) { // 获取方块当前的旋转角度(以欧拉角形式) let rotationX = this.node.eulerAngles.x; if (rotationX >= -160 && rotationX < -30) { this.ShowFront(); // 显示正面字 } else if(rotationX > 30 && rotationX <= 160) { this.ShowBack(); // 显示反面字 }else { this.ShowBothSides(); } } ShowFront() { this.txt.node.active = true; this.txt2.node.active = false; } ShowBack() { this.txt.node.active = false; this.txt2.node.active = true; } ShowBothSides() { this.txt.node.active = true; this.txt2.node.active = true; } set Text(value: string) { this.txt.string = value; this.txt2.string = value; } get Text() { return this.txt.string; } }