void OnMouseOver() { if (!hacked) { if (playerscript.Energy >= EnergyCost && playerControlScript.canHackComp) { Vector3 difference = player.transform.position - transform.position; GetComponent <Renderer>().material.color = InHackRange; if (inRange && Input.GetMouseButtonDown(1)) { RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position + difference.normalized * 10f, player.transform.position - transform.position, 1000f); foreach (RaycastHit2D r in hits) { if (r.transform.gameObject.tag == "Background") { break; } else if (r.transform.gameObject.tag.StartsWith("GateC")) { playerscript.SpendEnergy(EnergyCost); buttonController.StartCD(2); playerControlScript.StartCoroutine("HackCompRecovery"); Hacked(); break; } } } } else { GetComponent <Renderer>().material.color = OutOfHackRange; } } }
//For hacking enemies void HackEnemy(GameObject other, Vector3 otherpos) { /*if (this.GetComponentInParent<Player2DController> ().facingLeft) { * this.GetComponentInParent<Player2DController> ().Flip(); * }*/ int hackType = other.GetComponent <EnemyInfo>().enemyType; if (hackType != 2) { other.GetComponent <EnemyInfo>().isHacked = true; //Stops enemy movement anim.SetBool("IsHackingEnemy", true); anim.SetBool("HackedEnemyDead", false); StartCoroutine(HackEnemyAnim(other, hackType)); } else { anim.SetBool("IsHackingEnemy", true); other.GetComponent <Animator> ().SetBool("isHacked", true); StartCoroutine(HackHealthDroneAnim()); buttonController.StartCD(0); playerScript.StartCoroutine("HackRecovery"); } transform.parent.GetComponent <Player2DController> ().inHackingAnim = true; //Stop player from moving while hacking anim is playing transform.parent.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, 0f); if (otherpos.x < transform.position.x) //If player is to the right of target { if (!transform.parent.GetComponent <Player2DController> ().facingLeft) //If player is on the right while not facing left then flip to face left. { transform.parent.GetComponent <Player2DController> ().Flip(); } transform.parent.transform.position = new Vector3(otherpos.x + HorizHackTeleport, otherpos.y, transform.parent.transform.position.z); } else { if (transform.parent.GetComponent <Player2DController> ().facingLeft) //If player is on the left while facing left then flip to face right. { transform.parent.GetComponent <Player2DController> ().Flip(); } transform.parent.transform.position = new Vector3(otherpos.x - HorizHackTeleport, otherpos.y, transform.parent.transform.position.z); } }