public override void Attack() { GameObject arrow = new GameObject(_parent.transform.Position); arrow.transform.Rotation = _parent.transform.Rotation; RenderComponent textureComponent = WeaponCreator.GetArrow(); textureComponent.Sprite.Scale = _parent.GetScripts <CharacterScript>()[0].Weapon.GetComponent <RenderComponent>().Sprite.Scale / 2; arrow.AddComponent(textureComponent); Vector2D size = new Vector2D(textureComponent.Sprite.TextureRect.Height, textureComponent.Sprite.TextureRect.Width); RectangleCollider rc = new RectangleCollider(size * textureComponent.Sprite.Scale, false, 200); arrow.AddComponent(rc); Vector2D direction = Vector2D.Up().Rotate(arrow.transform.Rotation * (Math.PI / 180)); arrow.AddScript(new ArrowScript(direction, 2, Friendly)); arrow.transform.Position += direction.Normalize().Orthogonal() * 25; _addToEnvironment.Add(arrow); _arrows.Add(arrow); }
public void CheckCollision(List <ICollider> colliderList) { foreach (ICollider collider in colliderList) { foreach (ICollider colliderWith in colliderList) { if (collider != null && colliderWith != null) { if (collider != colliderWith) { if (collider is RectangleCollider) { RectangleCollider rectangleCollider = (RectangleCollider)collider; if (colliderWith is RectangleCollider) { RectangleCollider rectangleColliderWith = (RectangleCollider)colliderWith; //if (rectangleCollider.Parent.transform.Position.GetDistance(rectangleColliderWith.Parent.transform.Position) < (rectangleCollider.Size * 2).GetLength()) //{ if (rectangleCollider.IsCollided(rectangleColliderWith)) { rectangleCollider.Parent.CollisionHappened = true; rectangleCollider.Parent.CollidedWith = rectangleColliderWith; } //} } else if (colliderWith is SphereCollider) { SphereCollider sphereColliderWith = (SphereCollider)colliderWith; //if (rectangleCollider.Parent.transform.Position.GetDistance(sphereColliderWith.Parent.transform.Position) < (rectangleCollider.Size * 2).GetLength()) //{ if (rectangleCollider.IsCollided(sphereColliderWith)) { rectangleCollider.Parent.CollisionHappened = true; rectangleCollider.Parent.CollidedWith = sphereColliderWith; } //} } } else if (collider is SphereCollider) { SphereCollider sphereCollider = (SphereCollider)collider; if (colliderWith is RectangleCollider) { RectangleCollider rectangleColliderWith = (RectangleCollider)colliderWith; //if (sphereCollider.Parent.transform.Position.GetDistance(rectangleColliderWith.Parent.transform.Position) < (sphereCollider.Radius * 4)) //{ if (sphereCollider.IsCollided(rectangleColliderWith)) { sphereCollider.Parent.CollisionHappened = true; sphereCollider.Parent.CollidedWith = rectangleColliderWith; } //} } else if (colliderWith is SphereCollider) { SphereCollider sphereColliderWith = (SphereCollider)colliderWith; //if (sphereCollider.Parent.transform.Position.GetDistance(sphereColliderWith.Parent.transform.Position) < (sphereCollider.Radius * 4)) //{ if (sphereCollider.IsCollided(sphereColliderWith)) { sphereCollider.Parent.CollisionHappened = true; sphereCollider.Parent.CollidedWith = sphereColliderWith; } //} } } } } } } }
public void CheckCollision(List <ICollider> colliderList) { List <ICollider> test = new List <ICollider>(); foreach (ICollider item in colliderList) { if (item != null) { test.Add(item); //MyConsole.Out(((Component)item).Parent.ObjectName); } } for (int i = 0; i < test.Count; i++) { ICollider collider = test[i]; for (int k = 0; k < test.Count; k++) { ICollider colliderWith = test[k]; if (i != k) { if (collider is RectangleCollider) { RectangleCollider rectangleCollider = (RectangleCollider)collider; if (colliderWith is RectangleCollider) { RectangleCollider rectangleColliderWith = (RectangleCollider)colliderWith; //if (rectangleCollider.Parent.transform.Position.GetDistance(rectangleColliderWith.Parent.transform.Position) < (rectangleCollider.Size * 2).GetLength()) //{ if (rectangleCollider.IsCollided(rectangleColliderWith)) { //rectangleCollider.Parent.CollisionHappened = true; //rectangleCollider.Parent.CollidedWith = rectangleColliderWith; } //} } if (colliderWith is SphereCollider) { SphereCollider sphereColliderWith = (SphereCollider)colliderWith; //if (rectangleCollider.Parent.transform.Position.GetDistance(sphereColliderWith.Parent.transform.Position) < (rectangleCollider.Size * 2).GetLength()) //{ if (rectangleCollider.IsCollided(sphereColliderWith)) { //rectangleCollider.Parent.CollisionHappened = true; //rectangleCollider.Parent.CollidedWith = sphereColliderWith; } //} } } if (collider is SphereCollider) { SphereCollider sphereCollider = (SphereCollider)collider; if (colliderWith is RectangleCollider) { RectangleCollider rectangleColliderWith = (RectangleCollider)colliderWith; //if (sphereCollider.Parent.transform.Position.GetDistance(rectangleColliderWith.Parent.transform.Position) < (sphereCollider.Radius * 4)) //{ if (sphereCollider.IsCollided(rectangleColliderWith)) { //sphereCollider.Parent.CollisionHappened = true; //sphereCollider.Parent.CollidedWith = rectangleColliderWith; } //} } if (colliderWith is SphereCollider) { SphereCollider sphereColliderWith = (SphereCollider)colliderWith; //if (sphereCollider.Parent.transform.Position.GetDistance(sphereColliderWith.Parent.transform.Position) < (sphereCollider.Radius * 4)) //{ if (sphereCollider.IsCollided(sphereColliderWith)) { //sphereCollider.Parent.CollisionHappened = true; //sphereCollider.Parent.CollidedWith = sphereColliderWith; } //} } } } } } }