This script encapsulates the behaviour of a single shot, and can be attached and customised for each individual weaponshot prefabs. Once defined, the weaponshot prefab can be referenced in the weaponscontroller script when attached, both scripts/behaviour together define the weapons system.
Inheritance: NetworkBehaviour
コード例 #1
0
    void SwitchWeapon()
    {
        if (null != CurrentWeapon)
        {
            CurrentWeapon.SetActive(false);
        }

        CurrentWeaponType    = WeaponTypeToSwitchTo;
        WeaponTypeToSwitchTo = null;
        CurrentWeapon        = AvailableWeapons[(int)CurrentWeaponType];

        if (null != CurrentWeapon)
        {
            CurrentWeapon.SetActive(true);
            WeaponShot weapon = CurrentWeapon.GetComponent <WeaponShot>();

            if (null != weapon)
            {
                weapon.loaderSize = NextAmmoCount;

                if (NextAmmoCount > 0)
                { // Reset rocket laucher alpha
                    weapon.ResetRocketAlpha();
                }
            }
        }
    }
コード例 #2
0
ファイル: Game.cs プロジェクト: zyot249/Unity
    public void RemoveAll()
    {
        if (starships != null)
        {
            foreach (var ship in starships)
            {
                Starship shp = starships[ship.Key];
                Destroy(shp.gameObject);

                if (shp == myStarship)
                {
                    myStarship = null;
                }
            }
        }


        if (weaponShots != null)
        {
            foreach (var shot in weaponShots)
            {
                WeaponShot sht = weaponShots[shot.Key];

                if (sht != null)
                {
                    sht.Destroy();
                }
            }
        }

        weaponShots = new Dictionary <int, WeaponShot>();
        starships   = new Dictionary <int, Starship>();
    }
コード例 #3
0
    public override void OnEvent(WeaponFireEvent evnt)
    {
        GameObject prefab = Instantiate(WeaponFirePrefab);
        WeaponShot shot   = prefab.GetComponent <WeaponShot>();

        shot.StartPoint       = evnt.StartPoint;
        shot.EndPoint         = evnt.EndPoint;
        shot.BeamColor        = evnt.Color;
        shot.transform.parent = gameObject.transform;
    }
コード例 #4
0
 private void Inject(RayForFireProvider rayForFireProvider,
                     WeaponAim weaponAim,
                     WeaponShot weaponShot,
                     WeaponNoAmmo weaponMiss,
                     WeaponReload weaponReload)
 {
     _rayForFireProvider = rayForFireProvider;
     _weaponAim          = weaponAim;
     _weaponShot         = weaponShot;
     _weaponNoAmmo       = weaponMiss;
     _weaponReload       = weaponReload;
 }
コード例 #5
0
ファイル: Game.cs プロジェクト: zyot249/Unity
    public void removeWeaponShot(int id)
    {
        if (!weaponShots.ContainsKey(id))
        {
            return;
        }
        WeaponShot shot = weaponShots[id];

        // The shot could have already been removed if the explosion was notified by the server before the proximity update
        if (shot != null)
        {
            weaponShots.Remove(id);
            shot.Destroy();
        }
    }
コード例 #6
0
ファイル: Game.cs プロジェクト: zyot249/Unity
    public void explodeWeaponShot(int id, int posX, int posY)
    {
        if (!weaponShots.ContainsKey(id))
        {
            return;
        }
        WeaponShot shot = weaponShots[id];

        // The shot could have already been removed if the proximity update was notified before the explosion
        if (shot != null)
        {
            // Remove shot
            removeWeaponShot(id);
        }

        // Show explosion
        Vector3 newPos = Camera.main.ScreenToWorldPoint(new Vector3((float)posX, (float)posY, 0));

        newPos = new Vector3(newPos.x - Camera.main.transform.position.x, newPos.y - Camera.main.transform.position.y, 0);
        shot.Explode(newPos.x, newPos.y);
    }
コード例 #7
0
ファイル: Game.cs プロジェクト: zyot249/Unity
    public void createWeaponShot(int id, string type, float x, float y, float vx, float vy, int elapsed)
    {
        if (weaponShots.ContainsKey(id))
        {
            return;
        }
        WeaponShot shot = Instantiate(weaponObject, new Vector3(x, y, 0), Quaternion.identity) as WeaponShot;

        shot.id       = id;
        shot.settings = weaponTypes.GetSFSObject(type);

        // Add weapon shot to array container
        weaponShots.Add(id, shot);

        // Set position and velocity
        shot.xx             = x;
        shot.yy             = y;
        shot.velocity.vx    = vx;
        shot.velocity.vy    = vy;
        shot.lastRenderTime = getTimer() - elapsed;
    }
コード例 #8
0
    public void SpawnWeapon(GameObject weaponPrefab)
    {
        GameObject newWeapon = Instantiate <GameObject>(weaponPrefab, transform.position, transform.localRotation);

        newWeapon.transform.SetParent(m_manager.NewWeaponParent.transform, true);
        newWeapon.GetComponent <Rigidbody>().velocity = transform.right * m_fInitialVelocity;

        WeaponShot weaponShot = newWeapon.GetComponent <WeaponShot>();

        if (weaponShot)
        {
            weaponShot.InitializeLoader();
        }

        Weapon weapon = newWeapon.GetComponent <Weapon>();

        if (weapon)
        {
            weapon.SetSpawner(this);
        }

        m_manager.OnWeaponSpawned();
    }
コード例 #9
0
    void SwitchWeapon()
    {
        if (null != CurrentWeapon)
        {
            CurrentWeapon.SetActive(false);
        }

        CurrentWeaponType    = WeaponTypeToSwitchTo;
        WeaponTypeToSwitchTo = null;
        CurrentWeapon        = AvailableWeapons[(int)CurrentWeaponType];

        if (null != CurrentWeapon)
        {
            CurrentWeapon.SetActive(true);
            WeaponShot weapon = CurrentWeapon.GetComponent <WeaponShot>();

            if (null != weapon)
            {
                weapon.RemainingAmmos = NextAmmoCount;
                weapon.SetRocketVisibility(NextAmmoCount == 0);
            }
        }
    }
コード例 #10
0
ファイル: Game.cs プロジェクト: zyot249/Unity
    /**
     * Moves a weapon shot to the next position based on applied forces.
     * Same note about fake xx and yy coordinates apply here.
     */
    private void renderWeaponShot(WeaponShot shot)
    {
        // Update shot position due to the calculated velocity
        shot.xx += shot.velocity.vx;
        shot.yy += shot.velocity.vy;
        shot.transform.position = new Vector3(shot.xx, shot.yy, shot.transform.position.z);


        float now     = getTimer();
        float elapsed = now - shot.lastRenderTime;

        for (int i = 0; i < elapsed; i++)
        {
            shot.xx += shot.velocity.vx;
            shot.yy += shot.velocity.vy;
        }

        Vector3 newPos = Camera.main.ScreenToWorldPoint(new Vector3(shot.xx, shot.yy, 0));

        newPos = new Vector3(newPos.x - Camera.main.transform.position.x, newPos.y - Camera.main.transform.position.y, 0);

        shot.position       = new Vector2(newPos.x, newPos.y);
        shot.lastRenderTime = now;
    }