Esempio n. 1
0
    void Explode()
    {
        Destroy(gameObject);

        // Show effect
        Destroy(Instantiate(explosionEffect, transform.position, transform.rotation), 1f);

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider nearByObject in colliders)
        {
            Rigidbody rb = nearByObject.GetComponent <Rigidbody>();

            if (rb != null)
            {
                rb.AddExplosionForce(force, transform.position, radius);
            }

            EnemyBehaviourScript enemy = nearByObject.GetComponent <EnemyBehaviourScript>();

            if (enemy != null)
            {
                enemy.TakeDamage(damage);
            }
        }
    }
Esempio n. 2
0
    void Shoot()
    {
        muzzleflash.Play();
        gunSound.Play();

        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            print(hit.transform.name);

            EnemyBehaviourScript enemy = hit.transform.GetComponent <EnemyBehaviourScript>();

            if (enemy != null)
            {
                enemy.TakeDamage(damage);
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }

            GameObject impact = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impact, 3f);
        }
        print(remainingAmmo);
        remainingAmmo -= 1;
    }
Esempio n. 3
0
    public void CreateTopEnemy()
    {
        Vector3 pos   = new Vector3();
        float   speed = 0;

        if (Random.Range(0, 2) == 0)
        {
            pos   = new Vector3(23.5f, 2.3f, 18);
            speed = enemySpeed;
        }
        else
        {
            pos   = new Vector3(23.5f, 2.3f, -88);
            speed = -enemySpeed;
        }

        EnemyBehaviourScript newEnemy = Instantiate(enemy) as EnemyBehaviourScript;

        newEnemy.transform.parent   = transform;
        newEnemy.transform.position = pos;
        newEnemy.initSpeed          = speed;
        newEnemy.speed   = speed;
        newEnemy.initPos = pos;
        topEnemy         = newEnemy;
    }
Esempio n. 4
0
    void spawnEnemy(float speed, float health)
    {
        GameObject           en  = Instantiate(enemy, spawnPoint.transform.position + (Vector3.up * 0.02f), Quaternion.identity) as GameObject;
        EnemyBehaviourScript ebs = en.GetComponent <EnemyBehaviourScript>();

        ebs.health = health;
        ebs.setSpeed(speed);
    }
Esempio n. 5
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Enemy")
     {
         EnemyBehaviourScript ebs = other.GetComponent <EnemyBehaviourScript>();
         ebs.damage(damage);
         Destroy(this.gameObject);
     }
 }
Esempio n. 6
0
 void Update()
 {
     if (target == null || target.gameObject == null || (target.transform.position - transform.position).magnitude > att[0])
     {
         target       = null;
         targetScript = null;
     }
     if (target == null)
     {
         enemies = Physics.OverlapSphere(transform.position, att[0]);
         EnemyBehaviourScript temp;
         foreach (Collider c in enemies)
         {
             if (c.tag == "Enemy")
             {
                 temp = c.gameObject.GetComponent <EnemyBehaviourScript>();
                 if (target == null || temp.create < targetScript.create)
                 {
                     target       = c.gameObject;
                     targetScript = temp;
                 }
             }
         }
     }
     if (target != null)
     {
         desRot = Quaternion.LookRotation(getDesRot());
         if (Quaternion.Angle(gun.rotation, desRot) <= att[2] * Time.deltaTime)
         {
             gun.rotation = desRot;
             firing       = true;
             fire(getDesRot());
         }
         else
         {
             gun.rotation = Quaternion.RotateTowards(gun.rotation, desRot, att[2] * Time.deltaTime);
             //TODO play machine whiiring sound
             firing = false;
         }
     }
     else
     {
         firing = false;
     }
     shouldAnimate(firing);
 }
 public void NotifyStateChange(EnemyBehaviourScript.StateTypes state, GameObject defendTarget)
 {
     if (groupState != state)
     {
         switch(groupState)
         {
             case(EnemyBehaviourScript.StateTypes.eObjective):
             {
                 GenerateRandomWayPoint();
                 for (int i = 0; i < myLength; i++)
                 {
                     mySmalls[i].GetComponent<SmallEnemy>().myState = state;
                 }
                 break;
             }
             case(EnemyBehaviourScript.StateTypes.ePatrol):
             {
                 for (int i = 0; i < myLength; i++)
                 {
                     mySmalls[i].GetComponent<SmallEnemy>().myState = state;
                     mySmalls[i].GetComponent<SmallEnemy>().currentBigAlly = defendTarget;
                 }
                 break;
             }
             case(EnemyBehaviourScript.StateTypes.eRepel):
             {
                 GenerateRandomWayPoint();
                 for (int i = 0; i < myLength; i++)
                 {
                     mySmalls[i].GetComponent<SmallEnemy>().myState = state;
                 }
                 break;
             }
         }
         groupState = state;
     }
 }
Esempio n. 8
0
 private void OnEnable()
 {
     _enemyShip = target as EnemyBehaviourScript;
 }
Esempio n. 9
0
 void Start()
 {
     ebs = transform.parent.GetComponent <EnemyBehaviourScript>();
 }