void Update() { //increment timer to see if enough time has passed since previous attack timer = timer + Time.deltaTime; if ((timer >= timeBetweenAttacks) && hitEnemy && (playerHealth.currentHealth > 0)) { GetComponent <AudioSource>().Play(); //Attack (); //Debug.Log ("enemy hit: " + enemy.gameObject); if (enemy.gameObject == GameObject.Find("VacuumRoombaPos")) { vacHealth.TakeDamage(1); } else { if (enemy.gameObject != GameObject.Find("Security Camera")) { enemyHealthScript = enemy.GetComponent <EnemyHealth>(); enemyHealthScript.TakeDamage(1); } } timer = 0f; } }
void FixedUpdate() { if(shooting) { timer -= Time.deltaTime; GetComponent<AudioSource>().Play (); //Impact if(timer <= 0) { CreateProjectile(); shooting = false; RaycastHit hit; if(Physics.Raycast(transform.position, transform.forward, out hit, 50f)) { //Instantiate(shootingToast, hit.point, transform.rotation); //Destroy(shootingToast); Transform clone; // clone = Instantiate(shootingToast, transform.position, transform.position); // clone.rigidbody.AddForce(clone.transform.forward*shootForce); if(hit.transform.tag == "Enemy") // Destroy (hit.transform.gameObject); { vacHealth.TakeDamage(1); } if(hit.transform.tag == "Robot") { RobotHealth.TakeDamage(1); } if(hit.transform.tag == "Helicopter") { HelicopterHealth.TakeDamage(1); } if(hit.transform.tag == "SecurityCamera") { SecurityCameraHealth.TakeDamage(1); } //Debug.Log("hit something: " + hit.transform.tag); impacts[currentImpact].transform.position = hit.point; impacts[currentImpact].GetComponent<ParticleSystem>().Play(); if(++currentImpact >= maxImpacts) { currentImpact = 0; } //Destroy(projectile); } timer = .5f; } } }