コード例 #1
0
    public override void Step(Selectable sel)
    {
        UnitWeapon weap = sel.gameObject.GetComponentInChildren <UnitWeapon>();
        UnitBase   unit = sel.gameObject.GetComponent <UnitBase>();

        if (weap == null || unit == null)
        {
            return;
        }
        location = targetCombat.transform.position;
        unit.SetWeaponTarget(target);
        float distToTarget = (target.position - sel.transform.position).magnitude;

        ProjectileWeapon pw     = weap as ProjectileWeapon;
        bool             canSee = true;

        if (pw != null)
        {
            canSee = pw.CanSee(target.position);
        }

        if (distToTarget < weap.MaxRange && canSee)
        {
            //Don't move any closer
            sel.SetNavTarget(sel.transform.position);
        }
        else
        {
            sel.SetNavTarget(target.position);
        }
    }
コード例 #2
0
    public int SelectWeaponSlot(bool ranged)
    {
        int topCandidate = -1;
        int maxDamage    = -1;

        Item[] items = hostActor.hotbar.items;
        for (int i = 0; i < items.Length; i++)
        {
            ProjectileWeapon pw = items[i] as ProjectileWeapon;
            if (pw != null && ranged)
            {
                int dmg  = pw.GetBaseDamage().health;
                int ammo = pw.GetAmmoCount();
                if (maxDamage < dmg && ammo > 0)
                {
                    maxDamage    = dmg;
                    topCandidate = i;
                }
            }

            MeleeWeapon mw = items[i] as MeleeWeapon;
            if (mw != null && !ranged)
            {
                int dmg = mw.GetBaseDamage().health;
                if (maxDamage < dmg)
                {
                    maxDamage    = dmg;
                    topCandidate = i;
                }
            }
        }

        return(topCandidate);
    }
コード例 #3
0
ファイル: Item.cs プロジェクト: Rn4rc1s0/FPS_Project
    // Return an instance of the type's archetypal class.
    public static Item FromType(Types type)
    {
        Item ret = null;

        switch (type)
        {
        case Types.Hand: ret = new MeleeWeapon() as Item; break;

        case Types.Rifle: ret = new ProjectileWeapon() as Item; break;

        case Types.Bullet:
            ret           = new Projectile() as Item;
            ret.stackable = true;
            break;

        case Types.HealthPack:  ret = new HealthPowerUp() as Item; break;

        case Types.AmmoPack: ret = new AmmoPowerUp() as Item; break;

        case Types.Ammo:
            ret           = new Item();
            ret.stackable = true;
            break;

        case Types.AidHealthPack: ret = new HealthAid() as Item; break;
        }

        return(ret);
    }
コード例 #4
0
ファイル: ShipController.cs プロジェクト: maxbize/LD45
    public void NotifyPartDestroyed(ShipPart part)
    {
        parts.Remove(part);
        parts = parts.Where(p => p != null).ToList(); // HACK! Don't know why I need this. Single cockpit throws errors otherwise
        cameraManager.AddScreenShake(1.5f);

        Thrusters thruster = part.GetComponent <Thrusters>();

        if (thruster != null)
        {
            thrusters.Remove(thruster);
        }

        ProjectileWeapon weapon = part.GetComponent <ProjectileWeapon>();

        if (weapon != null)
        {
            weapons.Remove(weapon);
        }

        if (part.partName == "Cockpit")
        {
            // Inverse for loop because each death will modify parts with the callback
            Debug.LogFormat("Killing remaining {0} parts", parts.Count);
            for (int i = parts.Count - 1; i >= 0; i--)
            {
                // TODO: It would be really cool if we could show each part blowing up in succession
                parts[i].TakeDamage(parts[i].maxHealth);
            }
            Destroy(gameObject);
        }
    }
コード例 #5
0
    public override void Move(Vector2 dir, ProjectileWeapon weapon)
    {
        Rigidbody2D rigidBody = GetComponent <Rigidbody2D>();

        rigidBody.AddForce(dir * MoveSpeed);
        StartCoroutine(DoPebble());
    }
コード例 #6
0
    public virtual void Move(Vector2 dir, ProjectileWeapon weapon)
    {
        Rigidbody2D rigidBody = GetComponent <Rigidbody2D>();

        rigidBody.AddForce(dir * MoveSpeed);
        Invoke("Die", TimeToLive);
    }
コード例 #7
0
    private void OnCollisionEnter(Collision collision)
    {
        BulletCollider bulletCollider = collision.collider.GetComponent <BulletCollider>();

        if (bulletCollider)
        {
            ProjectileWeapon weapon = bulletCollider.GetComponent <ProjectileWeapon>();
            //dont do anything if this projectile collides with
            //the person who shot it
            if (weapon != firerWeapon)
            {
                bulletCollider.BulletCollision(this);

                if (bulletCollider.KillBullet)
                {
                    Kill();
                }
                else
                {
                    //It has a bullet collider but is set to not 'kill' the bullet.
                    //so we assume the bullet should 'Bounce' off the surface
                    foreach (ContactPoint c in collision.contacts) //Find collision point
                    {
                        rigid.velocity          = Quaternion.AngleAxis(180, c.normal) * transform.forward * -1;
                        rigid.velocity          = rigid.velocity.normalized * speed * timeManager.Coefficient;
                        rigid.transform.forward = rigid.velocity.normalized;
                    }
                }
            }
        }
    }
コード例 #8
0
    public void Attack(float delta)
    {
        attackTimer += delta;

        ProjectileWeapon pw = hostActor.PrimaryItem() as ProjectileWeapon;

        if (pw == null || pw.GetAmmoCount() == 0)
        {
            hostAi.ChangeState(StateAi.States.Fighting);
        }


        if (!aimDelayActive && attackTimer >= AttackInterval && aimed)
        {
            aimDelayTimer  = 0f;
            aimDelayActive = true;
        }

        if (aimDelayActive)
        {
            aimDelayTimer += delta;
            if (aimDelayTimer >= AimDelay)
            {
                aimDelayActive = false;
                attackTimer    = 0f;
                aimDelayTimer  = 0f;
                hostActor.Use(Item.Uses.A);
            }
        }
    }
コード例 #9
0
ファイル: WeaponBuilder.cs プロジェクト: el-pepi/Movil
    public GameObject Build(weaponType type)
    {
        GameObject go = WeaponFactory.instance.Create(type);

        switch (type)
        {
        case weaponType.pistol:
            ProjectileWeapon pistol = go.AddComponent <ProjectileWeapon> ();
            pistol.automatic  = false;
            pistol.weaponName = "Pistol";
            pistol.ammoType   = 0;
            break;

        case weaponType.submachine:
            ProjectileWeapon smg = go.AddComponent <ProjectileWeapon> ();
            smg.automatic  = true;
            smg.fireRate   = 0.1f;
            smg.weaponName = "SMG";
            smg.ammoType   = 0;
            break;

        case weaponType.rocket:
            ProjectileWeapon rl = go.AddComponent <ProjectileWeapon>();
            rl.automatic  = true;
            rl.fireRate   = 0.25f;
            rl.weaponName = "Rocket launcher";
            rl.ammoType   = 1;
            break;
        }
        return(go);
    }
コード例 #10
0
ファイル: TestUtil.cs プロジェクト: DrewCutch/SpellSword
        public static GameObject CreateGoblinArcher(Coord pos, Timeline timeline, GoalMapStore goalMapStore, MessageBus mainBus)
        {
            GameObject goblin = new UpdatingGameObject(pos, Layers.Main, null, timeline, isWalkable: true);

            Item mainWeapon = new ProjectileWeapon(new Damage(1), 5);

            Being goblinBeing = new Being(new SelectedAttributes(new AttributeSet(4, 5, 4, 4, 3)), goblins, new EquipmentSlotSet(), 2, "goblin");

            goblinBeing.Equipment.Equip(mainWeapon, EquipmentSlot.RightHandEquip);
            goblinBeing.Inventory.Add(gold, 10);

            Actor goblinActor = new Actor(goblinBeing, new BasicAgent(goalMapStore), mainBus);

            goblin.AddComponent(goblinActor);
            goblin.AddComponent(new GlyphComponent(new Glyph(Characters.g, Color.GreenYellow)));
            goblin.AddComponent(new NameComponent(new Title("a", "goblin")));

            EffectTargetComponent effectTarget = new EffectTargetComponent();

            effectTarget.EffectTarget.AddEffectReceiver(goblinActor);
            goblin.AddComponent(effectTarget);

            timeline.OnAdvance += goblinActor.Update;

            return(goblin);
        }
コード例 #11
0
ファイル: Unit.cs プロジェクト: w1shmast3r/STW2017.1.0-RTS
    void FireWeapon()
    {
        Base enemy = null;

        // turret.LookAt(target.transform);
        Vector3 offset    = Vector3.up * 0.5f;
        Vector3 direction = Vector3.Normalize((target.position + offset) - muzzle[0].transform.position);

        RaycastHit[] impacts = Physics.RaycastAll(muzzle[0].position, direction, weapon.range, attackMask);

        if (impacts.Length > 0)
        {
            for (int i = 0; i < impacts.Length; i++)
            {
                if (impacts[i].transform.root != transform.root)
                {
                    GameObject muzzleFlash = EffectRecycler.effectRecycler.GetEffect(weapon.muzzleFlash);
                    muzzleFlash.transform.parent        = muzzle[0];
                    muzzleFlash.transform.localPosition = Vector3.zero;
                    muzzleFlash.transform.localRotation = Quaternion.identity;
                    muzzleFlash.transform.localScale    = Vector3.one;
                    muzzleFlash.SetActive(true);

                    if (weapon.hasProjectile)
                    {
                        GameObject       projectile       = EffectRecycler.effectRecycler.GetEffect(weapon.projectileType);
                        ProjectileWeapon projectileScript = projectile.GetComponent <ProjectileWeapon>();
                        projectileScript.StartPosition = muzzle[0].position;
                        projectileScript.EndPosition   = impacts[i].point;
                        projectileScript.MyWeapon      = weapon;
                        projectileScript.Target        = impacts[i].transform.root.gameObject;
                        projectile.tag = transform.tag;
                        projectile.SetActive(true);

                        GetComponent <Animator>().SetInteger("state", 1);
                    }
                    else
                    {
                        //cache enemy base class
                        if (enemy == null)
                        {
                            enemy = impacts[i].transform.root.GetComponent <Base>();
                        }

                        GameObject hit = EffectRecycler.effectRecycler.GetEffect(weapon.hit);
                        hit.transform.position = impacts[i].point;
                        hit.SetActive(true);

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

                        break;
                    }
                }
            }
        }
    }
コード例 #12
0
 /// <summary>
 /// When entering the state we reset our shoot counter and grab our weapon
 /// </summary>
 public override void OnEnterState()
 {
     base.OnEnterState();
     _numberOfShoots   = 0;
     _shooting         = true;
     _weaponAim        = _characterHandleWeapon.CurrentWeapon.gameObject.MMGetComponentNoAlloc <WeaponAim>();
     _projectileWeapon = _characterHandleWeapon.CurrentWeapon.gameObject.MMGetComponentNoAlloc <ProjectileWeapon>();
 }
コード例 #13
0
 private void AdjustStatsToLevel(ProjectileWeapon shooter)
 {
     shooter.shootCooldown   = shootCooldowns[(int)level];
     shooter.projectileSpeed = projectileSpeeds[(int)level];
     shooter.bloom           = blooms[(int)level];
     shooter.pulseCount      = pulseCounts[(int)level];
     shooter.pulseInterval   = pulseIntervals[(int)level];
 }
コード例 #14
0
        public void Init(ProjectileWeapon weapon, Vector3 direction)
        {
            _weapon = weapon;
            _timeToLive = _weapon.TimeToLive;
            _direction = direction;

            transform.LookAt(_direction + transform.position);
        }
コード例 #15
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            ChangeWeapon(0);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            ChangeWeapon(1);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            ChangeWeapon(2);
        }

        if (Input.GetMouseButtonDown(0))
        {
            HandleLeftMouseButton();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            StartReload();
        }

        if (currentSelectedWeapon is ProjectileWeapon)
        {
            ProjectileWeapon selectedMissileWeapon = currentSelectedWeapon as ProjectileWeapon;
            switch (selectedMissileWeapon.ammoType)
            {
            case AmmoType.Rifle:
                weaponInfo.text = selectedMissileWeapon.weaponName + "\n" + selectedMissileWeapon.GetCurrentMagazineAmmo() + "/" + ammo[AmmoType.Rifle];
                break;

            case AmmoType.Rocket:
                weaponInfo.text = selectedMissileWeapon.weaponName + "\n" + selectedMissileWeapon.GetCurrentMagazineAmmo() + "/" + ammo[AmmoType.Rocket];
                break;

            case AmmoType.Laser:
                weaponInfo.text = selectedMissileWeapon.weaponName + "\n" + selectedMissileWeapon.GetCurrentMagazineAmmo() + "/" + ammo[AmmoType.Laser];
                break;

            case AmmoType.Smg:
                weaponInfo.text = selectedMissileWeapon.weaponName + "\n" + selectedMissileWeapon.GetCurrentMagazineAmmo() + "/" + ammo[AmmoType.Smg];
                break;

            case AmmoType.Shotgun:
                weaponInfo.text = selectedMissileWeapon.weaponName + "\n" + selectedMissileWeapon.GetCurrentMagazineAmmo() + "/" + ammo[AmmoType.Shotgun];
                break;
            }
        }
        else
        {
            weaponInfo.text = currentSelectedWeapon.weaponName;
        }
    }
コード例 #16
0
ファイル: Player_Weapons.cs プロジェクト: S-Reay/Cyber-Blood
    void Start()
    {
        missile = GetComponent <ProjectileWeapon>();
        shotgun = GetComponent <RayCastWeapon>();

        shotgun.enabled      = true;
        missile.enabled      = false;
        shotgunImage.enabled = true;
        missileImage.enabled = false;
    }
コード例 #17
0
    public void Fire(Vector2 fromWhere, Vector2 direction, Team firingTeam, ProjectileWeapon weaponInfo)
    {
        transform.position = fromWhere;
        transform.right    = direction.normalized;
        spawnTime          = Time.time;

        this.firingTeam = firingTeam;
        this.weaponInfo = weaponInfo;
        rb.velocity     = direction.normalized * weaponInfo.launchSpeed;
    }
コード例 #18
0
    /// <summary>
    /// Verifies whether the given GameObject is a weapon, and applies it to all slots in the array if it is.
    /// Returns the weapon if it was valid, and returns null otherwise.
    /// </summary>
    private GameObject ValidateWeapon(GameObject weapon)
    {
        // Remove pre-existing weapons so we can spawn new ones.
        FunctionDelegator.ExecuteWhenSafe(RemoveAllWeapons);

        // Check if a weapon prefab was specified.
        if (weapon == null)
        {
            // No prefab specified.
            return(null);
        }
        else
        {
            // Prefab specified, make sure it is actually a weapon, and if it is, whether the array supports it.
            ProjectileWeapon weaponScript = weapon.GetComponent <ProjectileWeapon>();
            if (weaponScript == null)
            {
                Debug.LogWarning("Speficied prefab does not contain a ProjectileWeapon script.", this);
                return(null);
            }
            else if (!CanEquipWeapon(weaponScript.Category))
            {
                Debug.LogWarning("Speficied weapon is not supported by this array.", this);
                return(null);
            }

            // Weapon specified, so fill the array with instances of that weapon.
            if (_weaponSlots.Count > 0)
            {
                foreach (Transform weaponSlot in _weaponSlots)
                {
                    if (weaponSlot != null)
                    {
                        // Make sure we only spawn weapon instances if this is a ship in the scene during play mode.
                        if (Application.isPlaying && !ExFuncs.IsPrefab(this))
                        {
                            FunctionDelegator.ExecuteWhenSafe(() =>
                            {
                                GameObject weaponInstance = Instantiate(weapon, weaponSlot.position, weaponSlot.rotation, weaponSlot);
                                _weapons.Add(weaponInstance.GetComponent <ProjectileWeapon>());
                            });
                        }
                    }
                    else
                    {
                        Debug.LogError("One of the weapon slot transforms in " + gameObject.name + " is null.", this);
                    }
                }
            }
        }

        // If we reached this point, the given prefab was a valid weapon, so we can return it.
        return(weapon);
    }
コード例 #19
0
    public override void SetShooterInterval()
    {
        for (int i = 0; i < shooters.Count; i++)
        {
            ProjectileWeapon current = shooters[i].GetComponent <ProjectileWeapon>();

            current.pulseCounter = current.pulseCount;
            current.pulseTimer   = 0;
            current.shootTimer   = offIntervals[shooterCount - 1][i];
        }
    }
コード例 #20
0
    public virtual void SetShooterInterval()
    {
        for (int i = 0; i < shooters.Count; i++)
        {
            ProjectileWeapon current = shooters[i].GetComponent <ProjectileWeapon>();

            current.pulseCounter = current.pulseCount;
            current.pulseTimer   = 0;
            current.shootTimer   = current.shootCooldown;
        }
    }
コード例 #21
0
    public override void Move(Vector2 dir, ProjectileWeapon weapon)
    {
        doMove   = true;
        startPt  = transform.position;
        endPt    = startPt + (new Vector3(dir.x, dir.y, 0) * Distance);
        currTime = 0;
        Rigidbody2D rigidBody = GetComponent <Rigidbody2D>();

        rigidBody.AddTorque(SpinSpeed);

        this.weapon = weapon;
    }
コード例 #22
0
ファイル: Present.cs プロジェクト: spacenerdy/TheJanglers
    public override void PickupObject()
    {
        int weaponNumber = Random.Range(0, projectileWeaponsToSpawn.Count - 1); //-1 because it starts counting at 0

        ProjectileWeapon projectileWeaponToSpawn = projectileWeaponsToSpawn[weaponNumber];

        GameObject spawnedWeapon = Instantiate(projectileWeaponToSpawn.gameObject, this.transform.position, Quaternion.identity);

        spawnPointParent.occupied = false;

        spawnedWeapon.GetComponent <ProjectileWeapon>().PickupObject();
        Destroy(this.gameObject);
    }
コード例 #23
0
    public override void Initialize(GameObject obj)
    {
        ProjectileWeapon weapon = obj.AddComponent <ProjectileWeapon>();

        weapon.totalAmmo       = totalAmmo;
        weapon.maxReloadedAmmo = maxReloadedAmmo;

        weapon.timeToReload     = timeToReload;
        weapon.timeBetweenShots = timeBetweenShots;

        weapon.projectile = projectile;

        //projectile.Initialize(obj);
    }
コード例 #24
0
ファイル: AmmoHud.cs プロジェクト: DanialVEVO/Gamelab2
 public void CheckHud()
 {
     if(currentWeapon.GetComponent<RaycastWeapon>() == currentWeapon.GetComponent<RaycastWeapon>()){
         rayCastClass = currentWeapon.GetComponent<RaycastWeapon>();
         ammoPool = string.Format("{0}", rayCastClass.ammoPool);
         currentAmmo = string.Format("{0}",rayCastClass.loadedMagazine);
     }
     else{
         projectileClass = currentWeapon.GetComponent<ProjectileWeapon>();
         ammoPool = string.Format("{0}", projectileClass.ammoPool);
         currentAmmo = string.Format("{0}", projectileClass.loadedMagazine);
     }
     SetHud();
 }
コード例 #25
0
ファイル: Lancer.cs プロジェクト: Fornan-II/Appetent_Synapse
    public virtual void AimAt(Transform target)
    {
        ProjectileWeapon weapon = null;

        if (equippedWeapon is ProjectileWeapon)
        {
            weapon = equippedWeapon as ProjectileWeapon;
        }

        Vector3 bodyVector = target.position;

        bodyVector.y = transform.position.y;

        Vector3 targetPos = target.position;

        if (weapon)
        {
            //Figure out how long the projectile will be in the air
            Vector3 aimVector = targetPos;
            aimVector -= weapon.barrel.position;
            aimVector -= Vector3.Project(aimVector, Physics.gravity);
            float travelTime = aimVector.magnitude / weapon.projectileInitSpeed;

            //Account for my velocity
            if (_rb)
            {
                targetPos += _rb.velocity * travelTime;
            }

            //Account for target velocity
            Rigidbody targetRB = target.GetComponent <Rigidbody>();
            if (targetRB)
            {
                targetPos += _rb.velocity * travelTime;
            }

            //Account for gravity
            targetPos -= Physics.gravity * (travelTime * travelTime);
        }

        //Aim things correctly
        transform.LookAt(bodyVector);
        equippedWeapon.transform.LookAt(targetPos);
        if (weapon)
        {
            weapon.barrel.LookAt(targetPos + Random.onUnitSphere * Innacuracy);
        }
    }
コード例 #26
0
    // Start is called before the first frame update
    public virtual void Init(ProjectileWeapon _stats, Vector3 _velocity, BHealth _target, BHealth _instigator)
    {
        stats = _stats;

        if (_target)
        {
            m_Target = _target.transform;
        }

        m_TargetPosition = transform.position;
        m_TargetRotation = transform.rotation;

        m_ConstantVelocity = _velocity;

        m_Instigator = _instigator.transform;
    }
コード例 #27
0
    /// <summary>
    /// Called when a new level gets started to load all the scripts for upgrades from the current
    /// players GameObject.
    /// </summary>
    private void GetUpgradeInfo()
    {
        dashUpgrade     = player.GetComponent <CharacterDash>();
        jumpUpgrade     = player.GetComponent <CharacterJump>();
        runUpgrade      = player.GetComponent <CharacterHorizontalMovement>();
        wallJumpUpgrade = player.GetComponent <CharacterWalljump>();
        glideUpgrade    = player.GetComponent <CharacterGlide>();
        swimUpgrade     = player.GetComponent <CharacterSwim>();
        healthUpgrade   = player.GetComponent <Health>();
        rockUpgrade     = player.GetComponent <RockHolder>();
        rockWeapon      = player.GetComponent <CharacterWeaponRockHandler>().CurrentWeapon.GetComponent <ProjectileWeapon>();
        projectilePool  = player.GetComponent <CharacterWeaponRockHandler>().CurrentWeapon.GetComponent <MMSimpleObjectPooler>();
        laserSight      = player.GetComponent <CharacterWeaponRockHandler>().CurrentWeapon.GetComponent <WeaponLaserSight>();
        DebugUpgrades();

        laserSight.enabled = false;
    }
コード例 #28
0
            public static void Postfix(ProjectileWeapon __instance, ref bool ___m_fullyBent)
            {
                if (IsManaBow(__instance) && ___m_fullyBent)
                {
                    var owner = __instance.OwnerCharacter;
                    var ammo  = owner.Inventory.Equipment.GetEquippedItem(EquipmentSlot.EquipmentSlotIDs.Quiver);
                    if (!ammo)
                    {
                        ___m_fullyBent = false;
                        owner.m_currentlyChargingAttack = false;
                        owner.BowRelease();

                        var charger = (WeaponCharger)__instance.GetExtension("WeaponCharger");
                        charger.ResetCharging();
                    }
                }
            }
コード例 #29
0
 // Token: 0x0600204F RID: 8271 RVA: 0x0009A760 File Offset: 0x00098960
 private IProjectile ShootProjectileFromSlot(int slot, Vector3 origin, Vector3 direction, int projectileID, bool explode, int actorID)
 {
     if (this.weaponSlots.Length > slot && this.weaponSlots[slot] != null)
     {
         ProjectileWeapon projectileWeapon = this.weaponSlots[slot].Logic as ProjectileWeapon;
         if (projectileWeapon != null)
         {
             projectileWeapon.Decorator.PlayShootSound();
             if (!explode)
             {
                 return(projectileWeapon.EmitProjectile(new Ray(origin, direction), projectileID, actorID));
             }
             projectileWeapon.ShowExplosionEffect(origin, Vector3.up, direction, projectileID);
         }
     }
     return(null);
 }
コード例 #30
0
    private void UpdateShooterCount()
    {
        foreach (Transform child in transform)
        {
            shooters.Remove(child.gameObject);
            Destroy(child.gameObject);
        }

        for (int i = 0; i < shooterCount; i++)
        {
            ProjectileWeapon newShooter = Instantiate(equippedWeapon, transform).GetComponent <ProjectileWeapon>();
            AdjustStatsToLevel(newShooter);

            shooters.Add(newShooter.gameObject);
        }

        SetShooterPattern();
    }
コード例 #31
0
 private void Equip(Item item)
 {
     if (item != equippedItem)
     {
         if (equippedItem != null)
         {
             Unequip();
         }
         equippedItem = item;
         itemInstance = Instantiate(selectedItem.itemPrefab);
         itemInstance.transform.parent = transform;
         ProjectileWeapon pw = itemInstance.GetComponent <ProjectileWeapon>();
         if (pw != null)
         {
             pw.projectileSpawnPoint = projectileSpawnPoint;
         }
     }
 }
コード例 #32
0
    private void OnTriggerEnter(Collider other)
    {
        BulletCollider bulletCollider = other.GetComponent <BulletCollider>();

        if (bulletCollider)
        {
            ProjectileWeapon weapon = bulletCollider.GetComponent <ProjectileWeapon>();
            //dont do anything if this projectile collides with
            //the person who shot it
            if (weapon != firerWeapon)
            {
                bulletCollider.BulletCollision(this);

                if (bulletCollider.KillBullet)
                {
                    Kill();
                }
            }
        }
    }
コード例 #33
0
ファイル: Upgraders.cs プロジェクト: DanialVEVO/Gamelab2
 public void GetVariables(GameObject currentWeapon)
 {
     if(currentWeapon.GetComponent<RaycastWeapon>() == currentWeapon.GetComponent<RaycastWeapon>()){
         raycastClass = currentWeapon.GetComponent<RaycastWeapon>();
         upgradeVariables[0] = (int)raycastClass.fireRatePerMinute;
         upgradeVariables[1] = raycastClass.maxPool;
         upgradeVariables[2] = raycastClass.damage;
         upgradeVariables[3] = (int)raycastClass.xSpreadMax;
     }
     else{
         projectileClass = currentWeapon.GetComponent<ProjectileWeapon>();
         upgradeVariables[0] = (int)projectileClass.fireRatePerMinute;
         upgradeVariables[1] = projectileClass.maxPool;
         upgradeVariables[2] = (int)projectileClass.fireSpeed;
         upgradeVariables[3]= projectileClass.grenade.GetComponent<ExplosiveProjectileScript>().enemyDamage;
         upgradeVariables[4]= (int)projectileClass.grenade.GetComponent<ExplosiveProjectileScript>().radius;
         //upgradeVariables[2] = projectileClass.power;
         //upgradeVariables[3] = projectileClass
     }
 }
コード例 #34
0
ファイル: ShipController.cs プロジェクト: sean-h/spacegame
    private Vector3 GetLeadPosition(ProjectileWeapon projectileWeapon, Ship target)
    {
        float theta = Mathf.Atan(targetShip.Velocity / projectileWeapon.projectileSpeed); //if projectile speed = 0, infinite speed
        float leadDistance = Vector3.Distance(ship.transform.position, target.transform.position) * Mathf.Sin(theta);
        Vector3 targetMoveDirection = targetShip.transform.forward;
        targetMoveDirection.Normalize();
        targetMoveDirection *= leadDistance;

        return (target.transform.position + targetMoveDirection);
    }