public bool MapCollision(Rigidbody rigidbody, bool horizontal, List <string> filterTags) { //グローバル座標をマップ座標に変換 Int2 position; Vector2 tempPosition; tempPosition.X = rigidbody.rectangleCollider.square.transform.position.X; tempPosition.Y = rigidbody.rectangleCollider.square.transform.position.Y; position = GetMapPositon(tempPosition); bool result = false; for (int i = -1; i < 2; i++) { for (int k = -1; k < 2; k++) { GameObject mapChip = GetMapChip(position.x + k, position.y + i); if (mapChip == null) { continue; } RectangleCollider mapCollider = (RectangleCollider)mapChip.GetComponent("RectangleCollider"); if (mapCollider.square.Intersects(rigidbody.rectangleCollider.square) && mapCollider != null) { mapCollider.gameObject.Hit(rigidbody.rectangleCollider); rigidbody.rectangleCollider.gameObject.Hit(mapCollider); if (filterTags.Contains(mapCollider.gameObject.tag)) { if (horizontal) { rigidbody.HorizontalHitBack(mapCollider); } else { rigidbody.VerticalHitBack(mapCollider); } result = true; } } } } return(result);; }
public bool MapCollision(Rigidbody rigidbody, bool horizontal) { //グローバル座標をマップ座標に変換 Int2 position; Vector2 tempPosition; tempPosition.X = rigidbody.rectangleCollider.square.transform.position.X; tempPosition.Y = rigidbody.rectangleCollider.square.transform.position.Y; position = GetMapPositon(tempPosition); bool result = false; //右側にある上中下3枚のマップチップと衝突判定 for (int i = -3; i < 4; i++) { for (int k = -3; k < 4; k++) { GameObject mapChip = GetMapChip(position.x + k, position.y + i); if (mapChip == null) { continue; } RectangleCollider mapCollider = (RectangleCollider)mapChip.GetComponent("RectangleCollider"); if (mapCollider.square.Intersects(rigidbody.rectangleCollider.square) && mapCollider != null) { if (horizontal) { rigidbody.HorizontalHitBack(mapCollider); } else { rigidbody.VerticalHitBack(mapCollider); } result = true; } } } return(result);; }
public RectangleCollider MapCollision(Rigidbody rigidbody, bool horizontal) { //グローバル座標をマップ座標に変換 Int2 position; Vector2 tempPosition; tempPosition.X = rigidbody.rectangleCollider.square.transform.position.X; tempPosition.Y = rigidbody.rectangleCollider.square.transform.position.Y; position = GetMapPositon(tempPosition); //右側にある上中下3枚のマップチップと衝突判定 for (int i = -3; i < 4; i++) { Console.WriteLine("試したるで"); for (int k = -3; k < 4; k++) { GameObject mapChip = GetMapChip(position.x + k, position.y + i); if (mapChip == null) { Console.WriteLine("見つからへん→" + (position.x + k) + ", " + (position.y + i)); continue; } RectangleCollider mapCollider = (RectangleCollider)mapChip.GetComponent("RectangleCollider"); if (mapCollider.square.Intersects(rigidbody.rectangleCollider.square) && mapCollider != null) { if (horizontal) { rigidbody.HorizontalHitBack(mapCollider); } else { rigidbody.VerticalHitBack(mapCollider); } } } } return(null); }
public override void Hit(RectangleCollider rectangleCollider) { }
public Rigidbody(Transform transform, RectangleCollider rectangleCollider) { this.transform = transform; this.rectangleCollider = rectangleCollider; }
public override void Hit(RectangleCollider rectangleCollider) { //何かと衝突した時に呼ばれる }