private void ApplyBorders() { int layer = 1 << gameObject.layer; GameObject borderGroup = new GameObject("Borders"); borderGroup.SetParentObject(transform); borderGroup.transform.localPosition = Vector2.zero; bool up = !Physics2D.OverlapPointAll(transform.position2D() + Vector2.up, layer) .Any(c => c.gameObject.name == name); bool down = !Physics2D.OverlapPointAll(transform.position2D() - Vector2.up, layer) .Any(c => c.gameObject.name == name); bool left = !Physics2D.OverlapPointAll(transform.position2D() - Vector2.right, layer) .Any(c => c.gameObject.name == name); bool right = !Physics2D.OverlapPointAll(transform.position2D() + Vector2.right, layer) .Any(c => c.gameObject.name == name); bool upRight = up || right || !Physics2D.OverlapPointAll(transform.position2D() + Vector2.up + Vector2.right, layer) .Any(c => c.gameObject.name == name); bool upLeft = up || left || !Physics2D.OverlapPointAll(transform.position2D() + Vector2.up - Vector2.right, layer) .Any(c => c.gameObject.name == name); bool downRight = down || right || !Physics2D.OverlapPointAll(transform.position2D() - Vector2.up + Vector2.right, layer) .Any(c => c.gameObject.name == name); bool downLeft = down || left || !Physics2D.OverlapPointAll(transform.position2D() - Vector2.up - Vector2.right, layer) .Any(c => c.gameObject.name == name); if (up) { GameObject2.Instantiate(topBorder, borderGroup.transform, Vector2.zero, Quaternion.identity); } if (left) { GameObject2.Instantiate(topBorder, borderGroup.transform, Vector2.zero, Quaternion.Euler(0, 0, 90)); } if (down) { GameObject2.Instantiate(topBorder, borderGroup.transform, Vector2.zero, Quaternion.Euler(0, 0, 180)); } if (right) { GameObject2.Instantiate(topBorder, borderGroup.transform, Vector2.zero, Quaternion.Euler(0, 0, 270)); } if (upRight) { GameObject2.Instantiate(topRightBorder, borderGroup.transform, Vector2.zero, Quaternion.identity); } if (upLeft) { GameObject2.Instantiate(topRightBorder, borderGroup.transform, Vector2.zero, Quaternion.Euler(0, 0, 90)); } if (downLeft) { GameObject2.Instantiate(topRightBorder, borderGroup.transform, Vector2.zero, Quaternion.Euler(0, 0, 180)); } if (downRight) { GameObject2.Instantiate(topRightBorder, borderGroup.transform, Vector2.zero, Quaternion.Euler(0, 0, 270)); } }
public void Should_Be_Able_To_Determine_Distance_To_Another_Entity() { var entityA = new GameObject1(); var entityB = new GameObject2(); entityA.Position = new Vector2( 100, 0 ); entityA.DistanceTo( entityB ).ShouldEqual( 100 ); entityA.Position = new Vector2( 0, 100 ); entityA.DistanceTo( entityB ).ShouldEqual( 100 ); }
public void Should_Be_Able_To_Determine_Distance_To_Another_Entity() { var entityA = new GameObject1(); var entityB = new GameObject2(); entityA.Position = new Vector2(100, 0); entityA.DistanceTo(entityB).ShouldEqual(100); entityA.Position = new Vector2(0, 100); entityA.DistanceTo(entityB).ShouldEqual(100); }
internal override void Move() { if (Direction.sqrMagnitude >= 0.001f) { GameObject2.transform.rotation = Quaternion.Euler(0, 0, Mathf.Sign(YDirection) * Vector3.Angle(Vector3.right, Direction) - 90); GameObject2.transform.position += Direction * Speed * Time.deltaTime; GameObject2.GetComponent <Animator>().SetBool("isWalk", true); //gameObject.GetComponent<Character>().audioSource.P } else { GameObject2.GetComponent <Animator>().SetBool("isWalk", false); } }