/// <summary> /// Инициализация /// </summary> protected override void Initialize() { base.Initialize(); Transform indicators = transform.FindChild("Indicators"); waterCheck = indicators.FindChild("WaterCheck"); groundCheck = indicators.FindChild("GroundCheck").GetComponent <WallChecker>(); wallCheck = indicators.FindChild("WallCheck").GetComponent <WallChecker>(); wallAboveCheck = indicators.FindChild("WallAboveCheck"); interactor = indicators.FindChild("Interactor").GetComponent <Interactor>(); immobile = false; jumping = false; onLadder = false; if (currentWeapon != null) { fightingMode = (currentWeapon is SwordClass) ? "melee" : "range"; } bag = new List <ItemClass>(); Collider2D[] cols = new Collider2D[2]; cols = GetComponents <Collider2D>(); col1 = cols[0]; col2 = cols[1]; col2.enabled = false; if (!PlayerPrefs.HasKey("Hero Health"))//Здоровье не восполняется при переходе на следующий уровень. Поэтому, его удобно сохранять в PlayerPrefs { PlayerPrefs.SetFloat("Hero Health", 12f); } Health = PlayerPrefs.GetFloat("Hero Health"); }
//check if there is a floor gap or wall or ceiling gap nearby public WallChecker wallChecks(Transform leftFoot, Transform rightFoot, Transform leftHead, Transform rightHead, LayerMask map, Transform bot) { WallChecker info = new WallChecker(false, null, null); RaycastHit2D leftWall = Physics2D.Raycast(bot.position, Vector2.left, 0.4f, map); RaycastHit2D rightWall = Physics2D.Raycast(bot.position, Vector2.right, 0.4f, map); RaycastHit2D leftCeiling = Physics2D.Raycast(leftHead.position, Vector2.up, 3f, map); RaycastHit2D rightCeiling = Physics2D.Raycast(rightHead.position, Vector2.up, 3f, map); RaycastHit2D leftGround = Physics2D.Raycast(leftFoot.position, Vector2.down, 3f, map); RaycastHit2D rightGround = Physics2D.Raycast(rightFoot.position, Vector2.down, 3f, map); //if the bot is super close to a wall, it needs to figure out what to do if ((leftWall.collider || rightWall.collider) && (leftGround.collider && rightGround.collider)) { info.wallNearby = true; } //check whether the bot has a ground opening to its left and right if (leftGround.collider && !rightGround.collider) { info.floorOpening = "right"; } else if (!leftGround.collider && rightGround.collider) { info.floorOpening = "left"; } else if (!leftGround.collider && !rightGround.collider) { info.floorOpening = "both"; } else { info.floorOpening = "none"; } //check whether the bot has ceiling to its left and right if (leftCeiling.collider && !rightCeiling.collider) { info.ceilingOpening = "right"; } else if (!leftCeiling.collider && rightCeiling.collider) { info.ceilingOpening = "left"; } else if (!leftCeiling.collider && rightCeiling.collider) { info.ceilingOpening = "both"; } else { info.ceilingOpening = "none"; } Debug.LogFormat("Wall nearby: {0}, Floor: {1}, Ceiling: {2}", info.wallNearby, info.floorOpening, info.ceilingOpening); return(info); }
private LayerMask mask = (1 << 11) | (1 << 13) | (1 << 16) | (1 << 17); //hookable, blue, wall, box layers void Start() { rb = GetComponent <Rigidbody2D>(); global = GameObject.Find("info").GetComponent <GlobalInfo>(); ground_checker = GameObject.Find("GroundChecker").GetComponent <GroundChecker>(); left = GameObject.Find("Left").GetComponent <WallChecker>(); right = GameObject.Find("Right").GetComponent <WallChecker>(); }
protected override void Initialize() { base.Initialize(); col = GetComponent <PolygonCollider2D>(); Transform indicators = transform.FindChild("Indicators"); wallCheck = indicators.FindChild("WallCheck").GetComponent <WallChecker>(); }
/// <summary> /// Инициализация /// </summary> protected override void Initialize() { base.Initialize(); Transform indicators = transform.FindChild("Indicators"); if (indicators != null) { wallCheck = indicators.FindChild("WallCheck").GetComponent<WallChecker>(); precipiceCheck = indicators.FindChild("PrecipiceCheck").GetComponent<WallChecker>(); } Patrol(); }
// Start is called before the first frame update void Start() { characterMovement = GetComponent <CharacterAnimBasedMovement>(); WallChecker = GetComponentInChildren <WallChecker>(); }