void Awake() { counter = 0; incorrect_counter = 0; filename = "collision_eval.txt"; time_stat_file = "time_stats.txt"; write_once = false; self = this.transform; self_ai = this.GetComponent<DoneEnemyAI>(); self_sight = this.GetComponent<DoneEnemySight>(); player = GameObject.FindGameObjectWithTag(DoneTags.player); player_health = player.GetComponent<DonePlayerHealth>(); animator_hash = GameObject.FindGameObjectWithTag(DoneTags.gameController).GetComponent<DoneHashIDs>(); GameObject[] enemies = GameObject.FindGameObjectsWithTag(DoneTags.enemy); for( int i = 0; i < enemies.Length; i++) { if ( self.transform == enemies[i].transform) { enemy_num = i + 1; } } }
void Update() { // if (Input.GetMouseButtonDown(0)) if (firing) { if (Time.time > lastFireTime + 1 / frequency) { // Spawn visual bullet Quaternion coneRandomRotation = Quaternion.Euler(Random.Range(-coneAngle, coneAngle), Random.Range(-coneAngle, coneAngle), 0); GameObject go = Spawner.Spawn(bulletPrefab, spawnPoint.position, spawnPoint.rotation) as GameObject; SimpleBullet bullet = go.GetComponent <SimpleBullet>(); lastFireTime = Time.time; // Find the object hit by the raycast RaycastHit hitInfo = raycast.GetHitInfo(); if (hitInfo.transform) { // Get the health component of the target if any Health targetHealth = hitInfo.transform.GetComponent <Health>(); if (targetHealth != null) { // Apply damage targetHealth.OnDamage(damagePerSecond / frequency, -spawnPoint.forward); } else { if (hitInfo.collider.tag == "Enemy") { DoneEnemyAI doneTargetHealth = hitInfo.transform.GetComponent <DoneEnemyAI>(); doneTargetHealth.takeDamage(damagePerSecond / frequency, -spawnPoint.forward); } else if (hitInfo.collider.tag == "Destroyable") { Destroyable target = hitInfo.transform.GetComponent <Destroyable>(); target.takeDamage(damagePerSecond / frequency); } } // Get the rigidbody if any if (hitInfo.rigidbody) { // Apply force to the target object at the position of the hit point Vector3 force = transform.forward * (forcePerSecond / frequency); hitInfo.rigidbody.AddForceAtPosition(force, hitInfo.point, ForceMode.Impulse); } // Ricochet sound // AudioClip sound = MaterialImpactManager.GetBulletHitSound (hitInfo.collider.sharedMaterial); // AudioSource.PlayClipAtPoint (sound, hitInfo.point, hitSoundVolume); bullet.dist = hitInfo.distance; } else { bullet.dist = 1000; } // OnStartFire(); } // StartCoroutine("OnStartFire"); } // else if (Input.GetMouseButtonUp(0)) // OnStopFire(); }