void Shoot() { if (canShoot) { maxBul = maxBul - 1; Vector2 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, (Camera.main.ScreenToWorldPoint(Input.mousePosition).y)); Vector2 firePointPosition = new Vector2(firePoint.position.x, firePoint.position.y); RaycastHit2D hit = Physics2D.Raycast(firePointPosition, mousePosition - firePointPosition, travDist, notToHit); Effect(); Debug.DrawLine(firePointPosition, (mousePosition - firePointPosition) * 100, Color.cyan); if (hit.rigidbody.GetComponent <Rigidbody2D>() != null) { Debug.DrawLine(firePointPosition, hit.point, Color.red); Debug.Log("you hit " + hit.collider.name); EnemyHealth health = hit.rigidbody.GetComponent <Collider2D>().GetComponent <EnemyHealth>(); health.TakeDamage(Damange); } if (hit.collider.tag == "Cyclops") { CyclopsAI cyclops = hit.collider.GetComponent <CyclopsAI>(); cyclops.Passiveness(); } } if (Melee) { Vector2 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, (Camera.main.ScreenToWorldPoint(Input.mousePosition).y)); Vector2 firePointPosition = new Vector2(firepoint2.position.x, firepoint2.position.y); RaycastHit2D hit = Physics2D.Raycast(firePointPosition, mousePosition - firePointPosition, travDist, notToHit); Debug.DrawLine(firePointPosition, (mousePosition - firePointPosition) * 100, Color.cyan); if (hit.rigidbody.GetComponent <Rigidbody2D>() != null) { Debug.Log(hit.rigidbody.name); Debug.DrawLine(firePointPosition, hit.point, Color.red); Debug.Log(hit.distance); EnemyHealth health = hit.collider.GetComponent <Collider2D>().GetComponent <EnemyHealth>(); health.TakeDamage(Damange); } } }
// Use this for initialization void Start() { // effect = GameObject.FindGameObjectWithTag("PlayerEffects").GetComponent<EnemyEffect>(); // write cylcops \/ cyclops = GameObject.FindGameObjectWithTag("Cyclops").GetComponent <CyclopsAI>(); }