From 788d87452dd97b5f1f8aad1c06f11d29bf83e609 Mon Sep 17 00:00:00 2001 From: Saibotk Date: Sun, 22 Apr 2018 23:59:13 +0200 Subject: [PATCH] Collision for bullet --- Assets/Prefabs/Bullet.prefab | 41 +++++++++++++++++++++++++++++++----- Assets/Scripts/Bullet.cs | 5 ++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Assets/Prefabs/Bullet.prefab b/Assets/Prefabs/Bullet.prefab index 83f6d32..2fa97c8 100644 --- a/Assets/Prefabs/Bullet.prefab +++ b/Assets/Prefabs/Bullet.prefab @@ -19,9 +19,10 @@ GameObject: serializedVersion: 5 m_Component: - component: {fileID: 4781595464190240} - - component: {fileID: 58664560518688016} - component: {fileID: 212185122411066660} - component: {fileID: 114075590146335024} + - component: {fileID: 61667207399653724} + - component: {fileID: 50031891945467640} m_Layer: 0 m_Name: Bullet m_TagString: Untagged @@ -42,8 +43,28 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!58 &58664560518688016 -CircleCollider2D: +--- !u!50 &50031891945467640 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1379543051791382} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 1 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 +--- !u!61 &61667207399653724 +BoxCollider2D: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} @@ -54,9 +75,19 @@ CircleCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 - m_Offset: {x: -0.0030702911, y: 0.0782015} + m_Offset: {x: -0.0035692453, y: 0.022604823} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1, y: 1} + newSize: {x: 10, y: 10} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 serializedVersion: 2 - m_Radius: 0.05788156 + m_Size: {x: 0.12197816, y: 0.23143363} + m_EdgeRadius: 0 --- !u!114 &114075590146335024 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/Assets/Scripts/Bullet.cs b/Assets/Scripts/Bullet.cs index 7fd2078..adbd22e 100644 --- a/Assets/Scripts/Bullet.cs +++ b/Assets/Scripts/Bullet.cs @@ -26,15 +26,14 @@ public class Bullet : MonoBehaviour { void Update () { if ( owner == null ) return; - transform.position = transform.position + transform.localRotation * Vector3.up * speed * Time.deltaTime; + transform.position = transform.position + transform.localRotation * Vector3.up * speed * Time.deltaTime; // TODO do with physics (rigidbody) } void OnCollisionEnter2D(Collision2D collision) { if ( owner == null ) return; - Debug.Log("Collided"); + if ( collision.collider.gameObject.tag != owner.tag ) { - Debug.Log("calc"); Mob m = collision.collider.gameObject.GetComponent(typeof(Mob)) as Mob; if (m != null) { m.InflictDamage(damage);