private void FixedUpdate() { timer += Time.fixedDeltaTime; animChangeTimer += Time.fixedDeltaTime; if (animChangeTimer >= TimeBeforeAnimChange) { if (crowdMembers.Length > 0) { GameObject lCrowdMember = crowdMembers[Mathf.FloorToInt(Random.Range(0, crowdMembers.Length))]; if (lCrowdMember) { Vampire lCharaScript = lCrowdMember.GetComponent <Vampire>(); if (lCharaScript != null) { lCharaScript.cycleThroughAnimations(); } } } animChangeTimer = 0.0f; } if (timer >= feedingRate) { // Get a random crowd member if (crowdMembers.Length > 0) { GameObject lCrowdMember = crowdMembers[Mathf.FloorToInt(Random.Range(0, crowdMembers.Length))]; if (lCrowdMember) { // Compute shooting direction Vector3 lTarget = new Vector3( player.transform.position.x + Random.Range(-maxInaccuracy, maxInaccuracy), player.transform.position.y, player.transform.position.z + Random.Range(-maxInaccuracy, maxInaccuracy) ); Vector3 lDirection = lTarget - lCrowdMember.transform.position; lDirection.y = 0; // Set the y axis //lDirection.y = Mathf.Clamp(Vector3.Distance(lCrowdMember.transform.position, lTarget),5, 15) + Random.Range(0,maxInaccuracy); // Compute shooting distance Vampire lCharacter = lCrowdMember.GetComponent <Vampire>(); // Character script DistanceWeapon lDistanceWeapon = lCharacter.distanceWeapon.GetComponent <DistanceWeapon>(); lDistanceWeapon.projectile = currentFoodType as GameObject; lDirection = lDistanceWeapon.transform.InverseTransformVector(lDirection); lDirection.Normalize(); lDistanceWeapon.ThrowDirection = lDirection; // shoot lCharacter.shoot(); } } timer = 0.0f; } }