void Shoot() { GameObject bul = Instantiate(bullet, transform.position, Quaternion.Euler(0f, transform.eulerAngles.y, 0f)) as GameObject; Debug.Log(gameObject); Physics2D.IgnoreCollision(bul.GetComponent <Collider2D>(), transform.parent.GetComponent <Collider2D>()); soulCollector.ChangeSouls(-1); audioSource.Play(); }
void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.tag == "Enemy" && !invulnerable) { soulCollector.ChangeSouls(-1); audioSource.Play(); rigidBody.velocity = new Vector2(0f, 0f); rigidBody.AddForce(new Vector2(-80f * transform.right.x, 10f) * 20 * Time.deltaTime, ForceMode2D.Impulse); invulnerable = true; // playerMovement.invulnerable = true; timer = 1.0f; } }
public void FixedUpdate() { if (Input.GetKeyDown(KeyCode.Mouse1)) { Vector3 targetPosition = transform.position; GameObject lightObject = Instantiate(lightPrefab, new Vector3(targetPosition.x, targetPosition.y, 0), Quaternion.identity) as GameObject; lights.Add(lightObject); if (lights.Count != 3) { soulCollector.ChangeSouls(-1); } } if (lights.Count == 2 && Vector2.Distance(lights[0].transform.position, lights[1].transform.position) < maxDistance) { RaycastHit2D[] rayHits = Physics2D.LinecastAll(lights[0].transform.position, lights[1].transform.position, LayerMask.GetMask("RayCast", "Ground")); Vector3 lineEnd = lights[1].transform.position; foreach (GameObject light in lights) { light.GetComponent <Animator>().SetBool("active", true); } foreach (RaycastHit2D hit in rayHits) { if (hit.collider.gameObject.tag == "Enemy") { // Matar al enemigo hit.collider.gameObject.SendMessage("Kill", null); } if (hit.collider.gameObject.tag == "Ground") { lineEnd = hit.point; break; } if (hit.collider.gameObject.tag == "Brazzier") { hit.collider.gameObject.SendMessage("Activate"); } } if (!existLine) { line = Instantiate(linePrefab, new Vector3((lights[0].transform.position.x + lineEnd.x) / 2, (lights[0].transform.position.y + lineEnd.y) / 2, 0f), Quaternion.identity) as GameObject; existLine = true; line.GetComponent <LineRenderer>().SetPosition(0, lights[0].transform.position); line.GetComponent <LineRenderer>().SetPosition(1, Vector2.Distance(lights[0].transform.position, lineEnd) * Vector3.Normalize(lineEnd - lights[0].transform.position) + lights[0].transform.position); sLAC.PlaySoulLink(); } } if (lights.Count == 3) { Destroy(line); existLine = false; sLAC.StopSoulLink(); foreach (GameObject light1 in lights) { Destroy(light1); } lights.Clear(); } }