// Update is called once per frame void Update() { // TODO Set the animation according with the state // Forcibly reverse the velocity, if going out of bounds if (this.transform.position.x <= PersonBrain.minHorPosition) { this.rbody.velocity = new Vector2(this.horizontalSpeed, 0.0f); } else if (this.transform.position.x >= PersonBrain.maxHorPosition) { this.rbody.velocity = new Vector2(-this.horizontalSpeed, 0.0f); } // Reactivate the AI, if it has finished running if (!isRunningAI) { this.runningCoroutine = StartCoroutine(doAI()); } if (this.dir != enDir.left && this.rbody.velocity.x < 0) { this.fixLayer.moveLeft(); this.dir = enDir.left; } else if (this.dir != enDir.right && this.rbody.velocity.x > 0) { this.fixLayer.moveRight(); this.dir = enDir.right; } }
/** * Initialize a interactive instance * * @param type The type of the person * @param color The color of the person */ public virtual void initInstance(enType type, enColor color, bool isPlayer = false) { Color32 c32; // Set the instance's properties this.type = type; this.color = color; // Make sure this person can be bribed/influenced this.state = enState.free; this.isWhite = false; this.dir = enDir.none; // Always start on idle forceAIState(enAIState.idle); this.sprBody = null; this.fixLayer = this.GetComponentInChildren<FixLayer>(); if (this.fixLayer != null) { this.fixLayer.fixLayer(this, isPlayer); this.sprBody = this.fixLayer.getBody(); } switch(type) { case enType.level_0: this.fixLayer.setType(0); break; case enType.level_1: this.fixLayer.setType(1); break; case enType.level_2: this.fixLayer.setType(2); break; } switch (this.color) { case enColor.red: c32 = new Color32(0xed, 0x6a, 0x6a, 0xff); break; case enColor.green: c32 = new Color32(0x3e, 0xb7, 0x79, 0xff); break; case enColor.blue: c32 = new Color32(0x54, 0x57, 0x9e, 0xff); break; case enColor.magenta: c32 = new Color32(0xda, 0x71, 0xb0, 0xff); break; case enColor.cyan: c32 = new Color32(0x69, 0xb6, 0xd3, 0xff); break; case enColor.yellow: c32 = new Color32(0xe1, 0xda, 0x4f, 0xff); break; case enColor.black: c32 = new Color32(0xff, 0xff, 0xff, 0xff); break; case enColor.white: c32 = new Color32(0xff, 0xff, 0xff, 0xff); break; default: c32 = new Color32(0xff, 0xff, 0xff, 0xff); break; } if (this.sprBody) { this.sprBody.color = new Color((float)c32.r / 255.0f, (float)c32.g / 255.0f, (float)c32.b / 255.0f); } // Randomize the position this.transform.position = new Vector3(Random.Range( PersonBrain.minHorPosition + 0.5f, PersonBrain.maxHorPosition - 0.5f), 0, 0); // Activate the object's physics/behavious/etc this.gameObject.SetActive(true); }