protected override void Awake() { base.Awake(); m_rigidBody2D = GetComponent <Rigidbody2D> (); m_surfaceDetector = GetComponent <SurfaceDetector> (); m_spriteRenderer = GetComponent <SpriteRenderer> (); m_attacker = GetComponent <Attacker> (); loadSkills(); }
public static Surface SurfaceFromCollision2D(Collision2D collision) { int enemiesLayer = LayerMask.NameToLayer("Enemies"); if (collision.collider.gameObject.layer == enemiesLayer) { Debug.Log("Touch enemy"); return(Surface.Enemy); } else { ContactPoint2D[] contact = new ContactPoint2D[2]; collision.GetContacts(contact); return(SurfaceDetector.SurfaceFromNormal(contact [0].normal)); } }
/// <summary> /// Raises the collision enter 2D event. /// </summary> /// /// <remarks> /// Activate the skill here. /// </remarks> /// /// <param name="collision">Collision.</param> private void OnCollisionEnter2D(Collision2D collision) { ContactPoint2D[] contacts = new ContactPoint2D[10]; collision.GetContacts(contacts); // Loop throug each contact point to see if player has come in contact with a wall foreach (ContactPoint2D contact in contacts) { Surface colliedSurface = SurfaceDetector.SurfaceFromNormal(contact.normal); if (colliedSurface == Surface.LeftWall || colliedSurface == Surface.RightWall) { m_colliedWall = true; m_rigidbody2D.drag = SlidingMultiplier; break; } } }