// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { gameObject.GetComponent <Animator>().SetBool("shooting", true); acumulateTime = waitShootTime; } if (gameObject.GetComponent <Animator>().GetBool("shooting")) { var playerPos = transform.parent.position; var diffPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - playerPos; var angle = Quaternion.Euler(0, 0, (-1) * (Mathf.Atan2(diffPos.x, diffPos.y) * Mathf.Rad2Deg)); transform.parent.rotation = Quaternion.Slerp(transform.parent.rotation, angle, 1.0f); acumulateTime += Time.deltaTime; if (acumulateTime > waitShootTime) { acumulateTime = 0; GameObject bullet_temp; bullet_temp = Instantiate(Bullet, Emiter.transform.position, Emiter.transform.rotation) as GameObject; Rigidbody2D Temp_RigidBody; Temp_RigidBody = bullet_temp.GetComponent <Rigidbody2D>(); Temp_RigidBody.AddForce(transform.up * force_bullet); Destroy(bullet_temp, 3.0f); } } if (Input.GetMouseButtonUp(0)) { gameObject.GetComponent <Animator>().SetBool("shooting", false); } }
void Update() { timer += Time.deltaTime; if ((delay * difficultyMulti) <= timer && active) { GameObject Temp_Projectile_Handler; Temp_Projectile_Handler = Instantiate(SphereMagenta, SpiralProjectileEmitter.transform.position, SpiralProjectileEmitter.transform.rotation) as GameObject; Rigidbody Temp_RigidBody; Temp_RigidBody = Temp_Projectile_Handler.GetComponent <Rigidbody>(); Temp_RigidBody.AddForce(transform.forward * (Forward_force * speedMulti)); Destroy(Temp_Projectile_Handler, 8f); timer = 0; Teleport(); } }
void Shoot() // Shoot following ray { GameObject BulletHolder; BulletHolder = Instantiate(Bullet, transform.position, transform.rotation) as GameObject; BulletHolder.transform.Rotate(Vector3.left * 90); Rigidbody Temp_RigidBody; Temp_RigidBody = BulletHolder.GetComponent <Rigidbody>(); Temp_RigidBody.AddForce(transform.forward * Force); Destroy(BulletHolder, 2.0f); }
private void AttackPlayer() // Attack player (currently with shooting) { agent.SetDestination(transform.position); transform.LookAt(player); if (!alreadyAttacked) // attack debounce // Attack code { RaycastHit hitPlayer; Ray playerPos = new Ray(transform.position, transform.forward); if (Physics.SphereCast(playerPos, 0.25f, out hitPlayer, fireRadius)) { if (Mathf.Floor(timerShots) <= 0 && hitPlayer.transform.tag == "Player") // Player in range, shoot { GameObject BulletHolder; BulletHolder = Instantiate(Bullet, transform.position, transform.rotation) as GameObject; BulletHolder.transform.Rotate(Vector3.left * 90); Rigidbody Temp_RigidBody; Temp_RigidBody = BulletHolder.GetComponent <Rigidbody>(); Temp_RigidBody.AddForce(transform.forward * Force); Destroy(BulletHolder, 2.0f); timerShots = timeBtwShots; } else { timerShots -= Time.deltaTime; } } alreadyAttacked = true; Invoke(nameof(ResetAttack), timeBetweenAttacks); } }