public void Shoot()
    {
        MuzzleFlash.Play();
        foreach (GameObject spawnpoint in Spawnpoints)
        {
            if (Physics.Raycast(spawnpoint.transform.position, spawnpoint.transform.forward, out RaycastHit hit))
            {
                //hit effects
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * ImpactForce);
                }
                GameObject impactFX = Instantiate(UsedImpactPrefab, hit.point, Quaternion.LookRotation(hit.normal, transform.up));
                impactFX.transform.SetParent(hit.collider.transform);

                //hitting an enemy turret
                if (hit.transform.CompareTag("EnemyTurret"))
                {
                    //instantiate a metal impact prefab
                    DeployableHealth hitHealth = hit.transform.GetComponent <DeployableHealth>();
                    hitHealth.Health -= 3f;
                }
            }
        }
        ShotBeamAmmoControl.CurrentAmmo--;
        NextFire = Time.time + Delay;
    }
Exemple #2
0
 }                                             //accesses the health script for this turret
 // Start is called before the first frame update
 protected override void Start()
 {
     base.Start();
     health = GetComponent <DeployableHealth>();
     Target = GameObject.FindWithTag("Player");
     Damp   = 2f;
 }