1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import Global from "./Global";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class NewClass extends cc.Component {
- /**0 for right */
- @property(Number)
- CliLorR: Number = 0;
- protected onEnable(): void {
- if (Math.random() < 0.5) {
- this.CliLorR = 0;
- }
- else {
- this.CliLorR = 1;
- }
- }
- start() {
- }
- update(dt) {
- if (this.CliLorR == 0) {
- this.node.parent.x++;
- let x = this.node.parent.isHold;
- if (x || this.node.parent.getComponent("GD").isHold) {
- Global.instance.LorR = 0;
- }
- if (this.node.parent.x > 160) {
- this.CliLorR = 1;
- }
- }
- else {
- this.node.parent.x--;
- let x = this.node.parent.isHold;
- if (x || this.node.parent.getComponent("GD").isHold) {
- Global.instance.LorR = 1;
- }
- if (this.node.parent.x < -160) {
- this.CliLorR = 0;
- }
- }
- }
- onCollisionEnter() {
- // if (this.CliLorR === 1) {
- // this.CliLorR = 0;
- // }
- // else {
- // this.CliLorR = 1;
- // }
- return
- if (this.CliLorR === 0) {
- this.CliLorR = 1;
- Global.instance.LorR = 1;
- // console.log("这里是CliGD的if"+Global.instance.LorR);
- }
- else {
- this.CliLorR = 0;
- Global.instance.LorR = 0;
- // console.log("这里是CliGD的else"+Global.instance.LorR);
- }
- }
- }
|