Beispiel #1
0
    void kill(DamageCause COD = DamageCause.Default)
    {
        print(gameObject.name + " suffered a death by " + COD.ToString());

        if (GetComponent <ShootingEnemy>() != null)
        {
            GetComponent <ShootingEnemy>().weapon.Drop();
            GameObject ammo = GameObject.CreatePrimitive(PrimitiveType.Cube);
            ammo.name = "DroppedAmmo";
            ammo.transform.Translate(transform.position);
            ammo.transform.Translate(0f, 0.5f, 0f);
            ammo.AddComponent(typeof(AmmoPickup));
            ammo.GetComponent <AmmoPickup>().ammoType = GetComponent <ShootingEnemy>().ammoType;          //GetComponent<ShootingEnemy>().ammo
            ammo.GetComponent <AmmoPickup>().Bullets  = GetComponent <ShootingEnemy>().ammo[(int)GetComponent <ShootingEnemy>().ammoType];
        }

        List <Enemy> es = PathfindingEnemy.listEnemies();

        es.Remove(thisEnemy);
        PathfindingEnemy.setTargets(PathfindingEnemy.listEnemies());
        foreach (Enemy e in PathfindingEnemy.targets)
        {
            if (e is PathfindingEnemy || e is ShootingEnemy)
            {
                (e as PathfindingEnemy).checkTarget();
                print("Calling checkTarget on " + e.name);
            }
        }
        Complete();
        gameObject.SetActive(false);
    }
Beispiel #2
0
    /// <summary>
    /// Shoots the gun from an AI, instead of a player.
    /// </summary>
    /// <returns>
    /// Wether the gun shot.
    /// </returns>
    /// <param name='camera'>
    /// The GameObject that is situated in place of a camera.
    /// </param>
    public virtual bool AIShoot(GameObject camera, Enemy shooter)
    {
        //Debug.Log("Attempting firing");
        if (CurAmmo > 0 && actionHasReset() && curAnim == weaponAnimType.None)
        {
            //Debug.Log("Firing by AI");
            CurAmmo -= 1;
            ((AudioSource)mainObject.GetComponent <AudioSource>()).Play();

            //Debug.Log("Setting anim clock to " + ((int)(30/(7.5*FireRateAsPercent / 100))) +
            //	", or " + (30/(7.5*FireRateAsPercent / 100)));
            //Debug.Log("Acheived via (30/(7.5*(" + FireRateAsPercent + "/100)))" );
            //Debug.Log("Acheived via " + 30/(7.5*FireRateAsPercent/100));
            isFiring = true;
            curAnim  = weaponAnimType.Firing;


            camera.transform.parent.Rotate(0, Random.Range(-maxRecoilSway, maxRecoilSway), 0);

            if (SmokePuff)
            {
                GameObject Thing = (GameObject)MonoBehaviour.Instantiate(SmokePuff, new Vector3(0, 0, 0), mainObject.transform.rotation);
                Thing.transform.parent        = mainObject.transform;
                Thing.transform.localPosition = SmokePuffPosition;
                //Thing.transform.Rotate(rot, Space.Self);
            }
            PathfindingEnemy.hearNoise(shooter, actualDetectionDistance);
            for (int i = 0; i < numOfShots; i++)
            {
                /*
                 * Vector3 aim = camera.transform.forward;
                 * //aim.Set (aim.x+Random.Range(-xSpread/10,xSpread/10), aim.y+Random.Range(-yspread/10,yspread/10), 0);
                 */
                Vector2 position = Random.insideUnitCircle;
                float   x        = position.x * xSpread;
                float   y        = position.y * yspread;
                // This defines a point half a meter in front of the shooter, bypassing all sorts of detection issues.
                Ray ray = new Ray(camera.transform.TransformPoint(Vector3.forward * 0.26f),
                                  camera.transform.forward.RotateX(x * Mathf.Deg2Rad).RotateY(y * Mathf.Deg2Rad));

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Range))
                {
                    generateHit(hit, shooter).calculateDamage();
                }
            }

            lastShot = Time.time;

            return(true);
        }
        return(false);
    }