示例#1
0
    IEnumerator hailFire(Transform user, Missile projectile)
    {
        yield return(new WaitForSeconds(delayTime));

        float startTime = Time.time;

        while (Time.time - startTime < lifeTime)
        {
            // Make sure user isn't dead
            if (user == null)
            {
                break;
            }
            if (projectile == null)
            {
                break;
            }

            yield return(new WaitForSeconds(intervalTime));

            Vector3 location = user.position + Vector3.up * heightOffset;                                                           // Get current height offset
            Missile newProj  = Instantiate(projectile, location + Random.insideUnitSphere * maxRadius, Quaternion.Euler(90, 0, 0)); // create new missile
            newProj.originator = projectile.originator;

            Rigidbody rbody = newProj.GetComponent <Rigidbody>(); // Get projectile rigidbody
            rbody.useGravity = true;                              // allow gravity
            newProj.GetComponent <Collider>().enabled = true;
            newProj.Activate();
            // newProj.originator = null;
        }
    }
示例#2
0
    public void FireMissile(Vector3 position, Quaternion rotation, Vector2 force)
    {
        if (CanFireMissile())
        {
            lastMissileShot = Time.time;
            Missile missile = MissileManager.Instance.GetMissile(FlyingObjType);

            missile.Activate(position, rotation, force);
        }
    }
示例#3
0
        public void Use()
        {
            if (this.missilePool.Count > 0)
            {
                GameObject top = this.missilePool.Dequeue();

                Missile missile = top.GetComponent <Missile>();

                Vector3 target = this.GetTarget();
                missile.Seek(target);
                missile.transform.position = new Vector3(target.x, target.y, 0f).normalized * 2f;
                top.SetActive(true);
                missile.Activate();

                // Add to the list of active missiles
                this.activePool.Add(top);
            }
        }
示例#4
0
    private void FireMissile()
    {
        /*
         * if (IsActive() && lastMissileShot + delayBetweenMissiles <= Time.time && _currMissiles > 0)
         * {
         *  lastMissileShot = Time.time;
         *  Missile missile = MissileManager.Instance.GetMissile(FlyingObjType);
         *
         *  missile.Activate(weaponTransform.position, transform.rotation, transform.up);
         *  ReduceMissiles();
         *  _animatorCannon.SetBool("shoot", true);
         * }
         */
        Missile missile = MissileManager.Instance.GetMissile(FlyingObjType);

        if (IsActive() && lastMissileShot + delayBetweenMissiles <= Time.time && _energyFuel.CanPerformAction(missile.EnergyCost))
        {
            lastMissileShot = Time.time;
            _energyFuel.PerformAction(missile.EnergyCost);
            missile.Activate(weaponTransform.position, transform.rotation, transform.up);
            _animatorCannon.SetBool("shoot", true);
        }
    }