//collision detection automatically called every frame void OnCollisionEnter2D(Collision2D col) { //with the Col parameter you can get a reference to the collided object if (col.transform.tag == "AIwarrior") { colAnimator = col.transform.GetComponent <Animator> (); Vector2 relativePosition = transform.InverseTransformPoint(col.transform.position); if (relativePosition.x < 0) { colAnimator.SetBool("isIdle", true); } } if (col.transform.tag == "playerArrow") { MovePlayerArrow arrowObject = col.gameObject.GetComponent <MovePlayerArrow>(); Rigidbody2D arrowBody = arrowObject.GetComponent <Rigidbody2D>(); arrowBody.isKinematic = true; health = health - PlayerArcherController.attackDamage; } if (col.transform.tag == "AIwarrior" && animator.GetBool("inRange") == false) { animator.SetBool("isIdle", true); } if (col.transform.tag == "AIarcher" && animator.GetBool("inRange") == false) { animator.SetBool("isIdle", true); } }
//collision detection automatically called every frame void OnCollisionEnter2D(Collision2D col) { //if an arrow has collided with the tower then reduce the health if (col.transform.tag == "playerArrow") { //get reference to arrow and set it to Kinematic so the Physics engine //does not cause the tower to flip over MovePlayerArrow arrowObject = col.gameObject.GetComponent <MovePlayerArrow>(); Rigidbody2D arrowBody = arrowObject.GetComponent <Rigidbody2D>(); arrowBody.isKinematic = true; currentHealth = currentHealth - PlayerArcherController.attackDamage; HandleHealth(); } }
void OnCollisionEnter2D(Collision2D col) { if (col.transform.tag == "Mine" && animator.GetBool("canWork") == false) { animator.SetBool("canWork", true); StartCoroutine(MineGold()); } if (col.transform.tag == "playerArrow") { MovePlayerArrow arrowObject = col.gameObject.GetComponent <MovePlayerArrow>(); Rigidbody2D arrowBody = arrowObject.GetComponent <Rigidbody2D>(); arrowBody.isKinematic = true; health = health - PlayerArcherController.attackDamage; } }