示例#1
0
 void OnCollisionEnter(Collision colision)
 {
     target       = colision.gameObject;
     targethealth = (HealthAndDeduction)target.GetComponent(typeof(HealthAndDeduction));
     if (targethealth != null)
     {
         targethealth.DamageCalc(incomDamage, Damage);
     }
     print("Bullet Detonated");
     Destroy(gameObject);
 }
示例#2
0
    //================================================================================================
    //LASER FIRE
    //================================================================================================
    void Laser()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, maxRange))
        {
            // Debug.Log(hit.transform.name + " found!");// declares if object was found
            //  print("Found a target game object distance of " + hit.distance);//Declares target distance



            target       = hit.collider.gameObject;//assigns target
            targethealth = (HealthAndDeduction)target.GetComponent(typeof(HealthAndDeduction));
            targethealth.DamageCalc(typeDamage, damage);

            // print("damaging target");//Declares when Target us damaged
            //   gameObject.SendMessage("DamageCalc", typeDamage, damage);
        }
        Debug.DrawLine(gameObject.transform.position, hit.point, Color.red, 1.0F);// draws firingline to target
    }
示例#3
0
    //FIRING MECHANISM
    private void Fire()
    {
        RaycastHit hit;

        //LASER HITSCAN
        if (typeWeapon == weaponType.laser)
        {
            Vector3 dir = transform.TransformDirection(Vector3.forward);
            if (Physics.Raycast(transform.position, dir, out hit, maxRange))
            {
                // Debug.Log(hit.transform.name + " found!");// declares if object was found
                //  print("Found a target game object distance of " + hit.distance);//Declares target distance

                Debug.DrawLine(gameObject.transform.position, hit.point, Color.red, 1.0F); // draws firingline to target

                target       = hit.collider.gameObject;                                    //assigns target
                targethealth = (HealthAndDeduction)target.GetComponent(typeof(HealthAndDeduction));
                targethealth.DamageCalc(typeDamage, damage);

                // print("damaging target");//Declares when Target us damaged
                //   gameObject.SendMessage("DamageCalc", typeDamage, damage);
            }
        }
//==============================================================================
        //MISSILE SPAWN
        if (typeWeapon == weaponType.missile)
        {                                                                    //spawns a clone projectile with a target location
            Vector3 dir = transform.TransformDirection(Vector3.forward);
            if (Physics.Raycast(transform.position, dir, out hit, maxRange)) //If target detected then fire
            {
                Vector3 offset = new Vector3(0, 0, 0);
                clone   = Instantiate(projectile, transform.position + offset, transform.rotation) as GameObject;
                target  = hit.collider.gameObject;//assigns target
                missile = (MissileScript)clone.GetComponent(typeof(MissileScript));
                missile.SetTarget(target);
                prevTarget = target;
                Debug.DrawLine(gameObject.transform.position, hit.point, Color.red, 1.0F);// draws firingline to target
                //    Debug.Log(hit.transform.name + " found!");// declares if object was found
                // print("Found a target game object distance of " + hit.distance);//Declares target distance
                //   print("firing missile");//Declares when Target us damaged
            }
            else if (target != null)  // if target not detected but target not null fire
            {
                Vector3 offset = new Vector3(0, 0, 0);
                clone   = Instantiate(projectile, transform.position + offset, transform.rotation) as GameObject;
                missile = (MissileScript)clone.GetComponent(typeof(MissileScript));
                missile.SetTarget(prevTarget);
            }
//==============================================================
        }//BULLET SPAWN
        if (typeWeapon == weaponType.turret)
        {//fires a cloned projectile
         //     print("Cannon Fire!");

            Vector3 offset           = new Vector3(0, 0, 0);
            Vector3 bulletTrajectory = new Vector3(0, 0, speed);
            clone = Instantiate(projectile, transform.position + offset, transform.rotation) as GameObject;
            //     bullet = (BulletScript)clone.GetComponent(typeof(BulletScript));

            clone.GetComponent <Rigidbody>().AddRelativeForce(bulletTrajectory);
        }
    }