Exemple #1
0
        public void Update()
        {
            if (game.NetworkManager == null || game.NetworkManager.GetType().Equals(typeof(ServerNetworkManager)))
            {
                if (LastWeaponReload.Add(ReloadWeapons) < DateTime.Now)
                {
                    Random randomizer = new Random();
                    int    quantity   = randomizer.Next((spawnPoints.Count - ActiveWeapons.Count) + 1);
                    if (ReloadWeapons.Seconds == 5)
                    {
                        quantity = spawnPoints.Count;
                    }
                    for (int i = 0; i < spawnPoints.Count && quantity > 0; i++)
                    {
                        if (!ActiveWeapons.ContainsKey(i))
                        {
                            var temp = new Tuple <Weapon, Box>(createWeapon(differentWeapons[randomizer.Next(differentWeapons.Length)]),
                                                               new Box(spawnPoints[i], 5, 5, 5));

                            ActiveWeapons.Add(i, temp);
                            ActiveWeapons[i].Item2.Tag = i;
                            ActiveWeapons[i].Item2.CollisionInformation.Events.ContactCreated  += ContactCreated;
                            ActiveWeapons[i].Item2.CollisionInformation.CollisionRules.Personal = BEPUphysics.CollisionRuleManagement.CollisionRule.NoSolver;
                            game.Space.Add(ActiveWeapons[i].Item2);
                        }
                    }
                    this.newWeaponsHaveBeenAdded = true;
                    ReloadWeapons    = new TimeSpan(0, 0, randomizer.Next(20, 61));
                    LastWeaponReload = DateTime.Now;
                }
            }
        }
Exemple #2
0
 public Weapon pickupWeapon(long weapon)
 {
     if (activeWeapons.ContainsKey(weapon))
     {
         var temp = ActiveWeapons[weapon];
         ActiveWeapons.Remove(weapon);
         game.Space.Remove(temp.Item2);
         return(temp.Item1);
     }
     return(null);
 }
Exemple #3
0
 //
 void removeWeapon()
 {
     if (weapons.Count != 0)
     {
         string LastAdded = weapons[w.wep.Count - 1];
         //
         // 1
         //
         GameObject FindLastAdded = GameObject.Find("" + LastAdded);
         DestroyImmediate(FindLastAdded);
         //
         // 2
         //
         activeWeap = FindObjectOfType <ActiveWeapons>();           // Reference to ActiveWeapons.
         activeWeap.Weapons.RemoveAt(activeWeap.Weapons.Count - 1); // Remove weapon from ActiveWeapons List
         startWeap = FindObjectOfType <StartWeapons>();             // Reference to StartWeapons.
         startWeap.Weapons.RemoveAt(startWeap.Weapons.Count - 1);   // Remove weapon from StartWeapons List
         GameObject FindLastAddedOnPanel = GameObject.Find("" + LastAdded);
         DestroyImmediate(FindLastAddedOnPanel);
         weapons.RemoveAt(weapons.Count - 1);
     }
 }
Exemple #4
0
    int i;                                                      // index of active Weapon in Active Weapons Array.
//
    void Awake()
    {
        try
        {
            active = FindObjectOfType <ActiveWeapons>(); // Referens to ActiveWeapons.
        }
        catch (NullReferenceException)
        {
            Debug.Log("There is no Active 'ActiveWeapons' panel in the Scene.");
        }
        Destroy(gameObject, destroyTime);                    // Destroy this gameObject after destroyTime.
        spriteRend = GetComponent <SpriteRenderer> ();       // Reference to gameObjects SpriteRenderer.
        try
        {
            // shoose Active Weapon randomly.
            i = UnityEngine.Random.Range(0, active.activeWeapons.Count);
        }
        catch (ArgumentOutOfRangeException)
        {
            Debug.Log("Could not add Ammo. You should have more than one weapon on weapon panel. Argument is out of Range.");
        }
        // Add different Ammo depending on 'Weapon' GameObject name.
        try
        {
            for (int k = 0; k < active.Weapons.Count; k++)
            {
                if (active.Weapons[k] == active.activeWeapons[i])
                {
                    onAddAmmo.Invoke();
                    ammo = ammoToAdd[k];
                }
            }
        }
        catch (ArgumentOutOfRangeException)
        {
            Debug.Log("Could not add Ammo. You should have more than one weapon on weapon panel. Argument is out of Range.");
        }
    }
Exemple #5
0
        //
        void createWeapon()
        {
            //
            // 1
            //
            // creating new "Weapon" Gameobject, parent it to weapon selection and add weaponMobile component.
            g = new GameObject("" + weaponName);
            g.AddComponent <weaponHolder>();
            if (WeaponImage)
            {
                g.GetComponent <SpriteRenderer>().sprite = WeaponImage;
            }
            W = GameObject.FindWithTag("WeaponSelection");// finding weaponSelection to parent new weapon to it.
            g.transform.SetParent(W.transform);
            //
            // create new GameObject and parent it to weapon.
            p = new GameObject("GameObject");
            p.transform.SetParent(g.transform);
            //
            // add name to new weapon
            string www = weaponName;

            g.name = www;
            weapons.Add(g.name); // add new weapon to "Weapons" ScriptableObject.
                                 //
            // 2
            //
            //adding new new Weapon on weapons panel.
            // creating new "Weapon" Gameobject, parent it to weapon panel and add Button and Image components.
            b = new GameObject("" + weaponName);
            b.AddComponent <Image>();
            b.GetComponent <Image>().sprite = WeaponImage;
            b.AddComponent <Button>();
            b.layer = 5;
            GameObject weaponpanel = GameObject.Find("Panel");// finding weapon Panel to parent new weapon to it.

            b.transform.SetParent(weaponpanel.transform);
            b.transform.localScale = new Vector3(1, 1, 1);
            //
            // create new Text GameObject and parent it to weapon.
            string[] results2             = AssetDatabase.FindAssets("_Weapons");
            string   ScriptableObjectpath = AssetDatabase.GUIDToAssetPath(results2[0]);

            w  = (Weapons)AssetDatabase.LoadAssetAtPath(ScriptableObjectpath, typeof(Weapons));
            pb = new GameObject(weaponName + "Ammo");
            pb.transform.SetParent(b.transform);
            pb.AddComponent <Text>();
            Text text = pb.GetComponent <Text>();

            text.font      = w.MainFont;
            text.fontSize  = 30;
            text.color     = new Color32(50, 50, 50, 255);
            text.alignment = TextAnchor.MiddleCenter;
            pb.layer       = 5;
            RectTransform TEXTrect = pb.GetComponent <RectTransform>();

            TEXTrect.localScale = new Vector3(1, 1, 1);
            TEXTrect.anchorMin  = new Vector2(0.6187f, 0f);
            TEXTrect.anchorMax  = new Vector2(1, 1);
            TEXTrect.offsetMin  = new Vector2(0, 0);
            TEXTrect.offsetMax  = new Vector2(20, 0);
            //
            activeWeap = FindObjectOfType <ActiveWeapons>(); // Reference to ActiveWeapons.
            activeWeap.Weapons.Add(b);                       // Add Weapon to Activeweapons List.
            weaponIndex = activeWeap.Weapons.Count - 1;
            startWeap   = FindObjectOfType <StartWeapons>(); // Reference to StartWeapons.
            startWeap.Weapons.Add(b);                        // Add Weapon to Activeweapons List.
                                                             //
            Button            butten  = b.GetComponent <Button>();
            WeaponSelection   waepsel = FindObjectOfType <WeaponSelection>();
            UnityAction <int> action  = new UnityAction <int>(waepsel.Select);

            UnityEventTools.AddIntPersistentListener(butten.onClick, action, weaponIndex);
            GameManager gameManager = FindObjectOfType <GameManager>();

            gameManager.WeaponsDamage.Add(weaponDamage);
        }
Exemple #6
0
        //
        void createWeaponFromPrefab()
        {
            pre      = Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            pre.name = prefab.name;
            weapons.Add(pre.name);                         // add new weapon to "Weapons" ScriptableObject.

            W = GameObject.FindWithTag("WeaponSelection"); // finding weaponSelection to parent new weapon to it.
            pre.transform.SetParent(W.transform);
            //
            // instantiate weapon prefab and parent it to weapon.

            // 2
            //
            //adding new new Weapon on weapons panel.
            // creating new "Weapon" Gameobject, parent it to weapon panel and add Button and Image components.
            b = new GameObject("" + pre.name);
            b.AddComponent <Image>();
            if (WeaponImage)
            {
                b.GetComponent <Image>().sprite         = WeaponImage;
                b.GetComponent <Image>().preserveAspect = true;
            }
            b.AddComponent <Button>();
            b.layer = 5;
            //Debug.Log("2");
            GameObject weaponpanel = GameObject.Find("Panel");// finding weapon Panel to parent new weapon to it.

            b.transform.SetParent(weaponpanel.transform);
            b.transform.localScale = new Vector3(1, 1, 1);
            //
            // create new Text GameObject and parent it to weapon.
            pb = new GameObject(pre.name + "Ammo");
            Debug.Log("3");
            pb.transform.SetParent(b.transform);
            pb.AddComponent <Text>();
            Debug.Log("4");
            Text text = pb.GetComponent <Text>();

            text.font      = w.MainFont;
            text.fontSize  = 30;
            text.color     = new Color32(50, 50, 50, 255);
            text.alignment = TextAnchor.MiddleCenter;
            pb.layer       = 5;
            RectTransform TEXTrect = pb.GetComponent <RectTransform>();

            TEXTrect.localScale = new Vector3(1, 1, 1);
            TEXTrect.anchorMin  = new Vector2(0.6187f, 0f);
            TEXTrect.anchorMax  = new Vector2(1, 1);
            TEXTrect.offsetMin  = new Vector2(0, 0);
            TEXTrect.offsetMax  = new Vector2(20, 0);
            //
            activeWeap = FindObjectOfType <ActiveWeapons>(); // Reference to ActiveWeapons.
            activeWeap.Weapons.Add(b);                       // Add Weapon to Activeweapons List.
            weaponIndex = activeWeap.Weapons.Count - 1;
            startWeap   = FindObjectOfType <StartWeapons>(); // Reference to StartWeapons.
            startWeap.Weapons.Add(b);                        // Add Weapon to Activeweapons List.
                                                             //
            Button            butten  = b.GetComponent <Button>();
            WeaponSelection   waepsel = FindObjectOfType <WeaponSelection>();
            UnityAction <int> action  = new UnityAction <int>(waepsel.Select);

            UnityEventTools.AddIntPersistentListener(butten.onClick, action, weaponIndex);
            GameManager gameManager = FindObjectOfType <GameManager>();

            gameManager.WeaponsDamage.Add(weaponDamage);
        }