void ShootTarget(ThiefHealth target) { m_IntervalTimer = 0; var bullet = Instantiate(m_Bullet, transform.position, Quaternion.identity); bullet.GetComponent <Bullet>().ShootTarget(target); }
void Awake() { // Set up the references. player = GameObject.FindGameObjectWithTag("Player").transform; anim = GetComponent <Animator>(); playerHealth = player.GetComponent <ThiefHealth>(); mechHealth = GetComponent <MechHealth>(); nav = GetComponent <UnityEngine.AI.NavMeshAgent>(); }
void Start() { m_Movement = GetComponent <ThiefMovement>(); m_Heath = GetComponent <ThiefHealth>(); m_State = State.Start; m_Timer = startDelaySeconds; // Random.Range(0f, m_MaxWaitTimeSec); m_StartPosition = transform.position; // Debug.Log("Start................."); }
void Shoot() { // Reset the timer. timer = 0f; //rotate body DIY_Movement.SoftLookAt(parent.gameObject, player.position, 30f); // Play the gun shot audioclip. gunAudio.Play(); // Enable the lights. gunLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range)) { // Try and find an EnemyHealth script on the gameobject hit. ThiefHealth playerHealth = shootHit.collider.GetComponent <ThiefHealth>(); // If the EnemyHealth component exist... if (playerHealth != null) { // ... the enemy should take damage. playerHealth.TakeDamage(damagePerShot); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); parent.GetComponent <MechMovement>().lostTarget = true; } }
void Update() { if (m_Thief == null) { return; } transform.position = Vector3.MoveTowards(transform.position, m_Thief.transform.position, m_Speed * Time.deltaTime); if (transform.position.Equals(m_Thief.transform.position)) { m_Thief.TakeDamage(m_Damage); m_Thief = null; Destroy(gameObject, 0.1f); } }
public void ShootTarget(ThiefHealth thief) { m_Thief = thief; }