// Use this for initialization void Awake() { SetInstanceOrSelfDestruct(this); // load and instantiate avatar prefab for each color (if too costly, link in inspector instead) avatarPrefabDict = new Dictionary <GameColor, GameObject>(); for (int playerNo = 1; playerNo <= 4; ++playerNo) { GameColor color = (GameColor)playerNo; // load prefab string colorName = color.ToString(); // alternative to players' info dict avatarPrefabDict[color] = ResourcesUtil.LoadOrFail <GameObject>("Character/Character_" + colorName); // instantiate inactive (SEO: better in Start?) if (createCharacters) { GameObject avatarInstance = avatarPrefabDict[color].InstantiateUnder(Locator.FindWithTag(Tags.CharacterParent).transform); m_Characters[playerNo - 1] = avatarInstance.GetComponentOrFail <CharacterMaster>(); avatarInstance.SetActive(false); } } remainingCharacterNb = 0; // the number of players may not be known at the time of Awake so put this somewhere else if needed }
private static void PrintChecker(GameColor color, bool isInBar) { Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor),color.ToString()); Console.Write(!isInBar ? "{0,6}" : "{0}", "O"); Console.ForegroundColor = ConsoleColor.DarkGray; }
void FixedUpdate() { RaycastHit2D groundHit = Physics2D.Raycast(transform.TransformPoint(new Vector2(0, -characterCollider.size.y / 2 + characterCollider.offset.y + .01f)), Vector2.down, groundDetectBuffer, LayerMask.GetMask(new string[] { GameColor.Black.ToString(), myGameColor.ToString() })); //Debug.DrawRay(transform.TransformPoint(new Vector2(0, -characterCollider.size.y / 2 + characterCollider.offset.y)), Vector2.down, Color.green, groundDetectBuffer); if (myJump == JumpState.jump) { if (jump < 3 && rb.velocity.y < 5) { Debug.Log(rb.velocity.y); rb.AddForce(new Vector2(0, jumpForce / jump), ForceMode2D.Impulse); if (rb.velocity.y > 0) { myJump = JumpState.rising; } else { myJump = JumpState.falling; } jump++; } } else if (myJump == JumpState.rising) { if (rb.velocity.y <= 0) { myJump = JumpState.falling; } } else if (myJump == JumpState.falling) { } if (groundHit) { if (Mathf.Abs(rb.velocity.y) < .1f) { if (myJump != JumpState.grounded) { myJump = JumpState.grounded; } if (jump > 1) { jump = 1; } } if (myMove == MoveState.right) { rb.velocity = new Vector2(runSpeed, rb.velocity.y); } else if (myMove == MoveState.left) { rb.velocity = new Vector2(-runSpeed, rb.velocity.y); } else { if (Mathf.Abs(rb.velocity.x) > .1f) { rb.velocity = new Vector2(rb.velocity.x * (1 - (deaccelerationMultiplyer / 10)), 0); } else { rb.velocity = new Vector2(0, rb.velocity.y); } } } }
private static Piece[] GeneratePawns(GameColor color) { int yOffset = 64; if (color == GameColor.White) { yOffset = 384; } Piece[] pieces = new Piece[8]; for (int i = 0; i < pieces.Length; i++) { pieces[i] = new Pawn(9 + i, new Vector2(i, yOffset / 64), new Vector2(64 * i, yOffset), ResourceManager.Instance.Textures[color.ToString().ToLower() + "_pawn"], color); } return(pieces); }