Пример #1
0
    private void Init()
    {
        battery = GetComponentInChildren<GunBehaviour>();

        battery.Bullet = bullet;
        battery.Gun = gun;
    }
Пример #2
0
 public void BroadcastSwitchGun(GunBehaviour gunBehaviour)
 {
     if (SwitchGunListener != null)
     {
         SwitchGunListener(gunBehaviour);
     }
 }
Пример #3
0
    void Start()
    {
        _gunBehaviour       = Gun.GetComponent <GunBehaviour>();
        _rectTransform      = this.GetComponent <RectTransform>();
        newAnchoredPosition = _rectTransform.pivot;

        bullets = new Stack <GameObject>();
    }
Пример #4
0
    //https://unity3d.com/learn/tutorials/projects/space-shooter/shooting-shots?playlist=17147
    void Update()
    {
        GunBehaviour gun = logicScript.retGun().GetComponent <GunBehaviour>();

        if ((Input.GetKey(KeyCode.Space) || Input.touchCount > 0) && Time.time > nextFire)
        {
            Instantiate(gun, Cannon.position, Cannon.rotation);
            nextFire = Time.time + gun.fireRate;
        }
    }
Пример #5
0
 public void SwitchWeapon()
 {
     if (Input.GetMouseButtonDown(0) && gun.GetType() == "MachineGun")
     {
         gun = gunController.GetComponent <ShotgunBehaviour>();
     }
     else if (Input.GetMouseButtonDown(0) && gun.GetType() == "Shotgun")
     {
         gun = gunController.GetComponent <MachineGunBehaviour>();
     }
 }
Пример #6
0
    void Awake()
    {
        m_menuAnim         = GetComponent <Animator>();
        m_visible          = false;
        m_player           = GameObject.FindGameObjectWithTag("Player");
        m_playerController = m_player.GetComponent <PlayerController>();

        m_gunBehav = GameObject.FindObjectOfType <GunBehaviour>();
        m_rBehav   = GameObject.FindObjectOfType <RLauncherBehaviour>();

        // Default weapon:
        m_currWeapon = m_gunBehav;
    }
Пример #7
0
    // Use this for initialization
    void OnMouseDown()
    {
        if (!isDestroying)
        {
            if (gun == null)
            {
                gun = GunsManager.currentGun.GetComponent <GunBehaviour>();
            }

            ItemSpawner.ammoOnScene--;

            gun.AddAmmo(10);

            EventsManager.Instance.BroadcastUpdateBulletsCounter();
            isDestroying = true;
            Destroy(gameObject, 0.2f);
        }
    }
Пример #8
0
    /// <summary>
    /// Shoot a bullet from gun point!
    /// </summary>
    public void Shoot(GunBehaviour gunBehaviour)
    {
        //TODO Do this with new POOL!!!! POOL POOL POOL
        //Get a bullet
        GameObject bullet = Instantiate(bulletPrefab);

        Bullet b = bullet.GetComponent <Bullet> ();

        b.ownerTeam = gunBehaviour.team;

        //Get rigid bullet
        Rigidbody2D rigid = bullet.GetComponent <Rigidbody2D>();


        //SHOOT with transform info
        bullet.transform.position = gunBehaviour.GunBulletPoint.position;
        bullet.transform.rotation = gunBehaviour.GunBulletPoint.rotation;

        rigid.velocity = gunBehaviour.GunBulletPoint.right * BulletSpeed.Value;
    }
Пример #9
0
	// Use this for initialization
	void Start () {
		_player = Player.current.transform;
		_gun = GunBehaviour.Gun;
	}
Пример #10
0
 private void Awake()
 {
     inventory     = GetComponent <AllGunStatus>();
     weaponManager = GetComponent <WeaponManager>();
     gunBehaviour  = GetComponentInChildren <GunBehaviour>();
 }
	void Start () 
	{
		hasGun = false;
		hasKey = false;
		health = 1;
	
		audio.playOnAwake = false;

		pickupGUI = GameObject.Find ("GUIText_displaymessagetouser").GetComponent<DisplayMessageToUser>();
		healthBarUpdate = GameObject.Find ("healthbar").GetComponent<HealthBar>();
		guiAmmo = GameObject.Find ("GUIText_ammo");
		crosshairObject = GameObject.Find ("GUITexture_crossHair");
		gunAmmo = gameObject.GetComponent<GunBehaviour>();

		ChangeGUITexture(false, "Gun");
		ChangeGUITexture(false, "Key");
	}
Пример #12
0
 void OnDestroy()
 {
     Gun = null;
 }
Пример #13
0
 protected override void OnAwake()
 {
     Gun = this;
 }
Пример #14
0
 // Start is called before the first frame update
 void Start() => battery = GetComponentInChildren<GunBehaviour>();
Пример #15
0
 // Use this for initialization
 void Start()
 {
     _player = Player.current.transform;
     _gun    = GunBehaviour.Gun;
 }
Пример #16
0
    public bool AddItem(int id)
    {
        ItemData itemToAdd = database.FetchItemByID(id);

        if (itemToAdd != null)
        {
            int existingItemIndex = FindFirstItemInInventory(itemToAdd.ID);

            //stack if item is stackable and already in inventory (-1 = no existing item)
            if (itemToAdd.Stackable && existingItemIndex != -1)
            {
                UIItem existingUIItem = inventorySlots [existingItemIndex].GetComponentInChildren <UIItem> ();
                existingUIItem.amount++;
                existingUIItem.transform.GetComponentInChildren <Text> ().text = existingUIItem.amount.ToString();

                return(true);
            }
            else
            {
                //new item not present in inventory

                for (int i = 0; i < inventoryItems.Count; i++)
                {
                    //if there is a free slot
                    if (inventoryItems [i].ID == -1)
                    {
                        inventoryItems [i] = itemToAdd;

                        //create visualization for item, position relative to parent slot
                        GameObject itemObject   = Instantiate(inventoryItem);
                        UIItem     itemUIObject = itemObject.gameObject.GetComponent <UIItem> ();
                        itemUIObject.item = itemToAdd;

                        //OPTIMISE: remember item original slot for Drag'n'Drop logic, a bit messy
                        itemUIObject.slotID = i;
                        itemUIObject.amount = 1;

                        //positioning and hierarchy
                        itemObject.transform.SetParent(inventorySlots [i].transform);
                        itemObject.transform.localPosition = Vector2.zero;

                        itemObject.GetComponent <Image> ().sprite = itemToAdd.Sprite;
                        itemObject.name = itemToAdd.Title;

                        //UGLY-ASS TEMPORARY CODE FIXME
                        List <string> availableGuns = new List <string> {
                            "revolver", "shotgun", "rifle"
                        };

                        List <string> availableProjectiles = new List <string> {
                            "throwing_knife"
                        };

                        //if gun
                        if (availableGuns.Contains(itemToAdd.Slug))
                        {
                            GunBehaviour gunLogic = itemObject.AddComponent <GunBehaviour> ();
                            gunLogic.GunData = Resources.Load("scriptable_objects/guns/" + itemToAdd.Slug) as GunData;

                            gunLogic.InitialChecks();
                        }
                        //if knifes
                        else if (availableProjectiles.Contains(itemToAdd.Slug))
                        {
                            ThrowBehaviour throwLogic = itemObject.AddComponent <ThrowBehaviour> ();
                            throwLogic.ProjectileData = Resources.Load("scriptable_objects/projectiles/" + itemToAdd.Slug) as ProjectileData;

                            throwLogic.InitialChecks();
                        }

                        //if clothing
                        if (itemToAdd.Type == ItemData.ItemType.clothing)
                        {
                            ClothingBehaviour clothingLogic = itemObject.AddComponent <ClothingBehaviour> ();
                            clothingLogic.associatedItem = itemToAdd;
                            clothingLogic.itemInstance   = itemObject.GetComponent <UIItem> ();
                            clothingLogic.spriteSwitcher = playerAnimationManager.bodySprites[(int)itemToAdd.Clothing];
                        }

                        if (itemToAdd.CanBeEquipped)
                        {
                            //equip this object (and de-equip similar type items if not clothing)
                            EquipItem(itemUIObject, true);
                        }

                        //don't add the item to every free slot: get out of the loop!
                        return(true);
                    }
                }

                return(false);
            }
        }
        else
        {
            Debug.Log("Couldn't find item to add (id = " + id);
            return(false);
        }
    }
Пример #17
0
        public override void OnInspectorGUI()
        {
            //public LayerMask layers;

            serializedObject.Update();
            GunBehaviour targetscript = (GunBehaviour)target;

            //---------------------------------------------------------------------------------------------------------------------------------------------
            EditorGUILayout.LabelField("Camera GameObject", EditorStyles.boldLabel);
            targetscript.cam_go = (GameObject)EditorGUILayout.ObjectField(targetscript.cam_go, typeof(GameObject), true);
            EditorGUILayout.HelpBox("In this field you put the camera which the player is using. This can not be empty", MessageType.Warning);
            //---------------------------------------------------------------------------------------------------------------------------------------------

            //---------------------------------------------------------------------------------------------------------------------------------------------
            EditorGUILayout.LabelField("Bullet GameObject", EditorStyles.boldLabel);
            targetscript.bullet = (GameObject)EditorGUILayout.ObjectField(targetscript.bullet, typeof(GameObject), true);
            EditorGUILayout.HelpBox("In this field you put the bullet that the weapon shoots", MessageType.Info);
            //---------------------------------------------------------------------------------------------------------------------------------------------


            //---------------------------------------------------------------------------------------------------------------------------------------------
            EditorGUILayout.LabelField("ShotPoint", EditorStyles.boldLabel);
            targetscript.shotpoint = (GameObject)EditorGUILayout.ObjectField(targetscript.shotpoint, typeof(GameObject), true);
            EditorGUILayout.HelpBox("In this field you put the spawnpoint for the bullet", MessageType.Info);
            //---------------------------------------------------------------------------------------------------------------------------------------------

            //---------------------------------------------------------------------------------------------------------------------------------------------
            targetscript.WantsBump = EditorGUILayout.Toggle("Wants Bump", targetscript.WantsBump);

            if (targetscript.WantsBump == true)
            {
                targetscript.player_With_Rigidbody = (GameObject)EditorGUILayout.ObjectField("Player with RigidBody", targetscript.player_With_Rigidbody, typeof(GameObject), true);
                targetscript.BumpForce             = EditorGUILayout.FloatField("Bump Force", targetscript.BumpForce);
            }

            //---------------------------------------------------------------------------------------------------------------------------------------------
            EditorGUILayout.LabelField("Inputs", EditorStyles.largeLabel);

            targetscript.FireButton    = EditorGUILayout.TextField("Fire Button", targetscript.FireButton);
            targetscript.RealoadButton = EditorGUILayout.TextField("Reload Button", targetscript.RealoadButton);
            //------------------------------------------ERROOO---------------------------------------------------------------------------------------------------

            //EditorGUILayout.LabelField("Layers", EditorStyles.boldLabel);
            //targetscript.layers = EditorGUILayout.LayerField(targetscript.layers.value, targetscript.layers);


            //------------------------------------------ERROOO---------------------------------------------------------------------------------------------------

            EditorGUILayout.LabelField("Ammo Info", EditorStyles.largeLabel);

            targetscript.maxMagazineSize        = EditorGUILayout.IntField("Max Magazine Size", targetscript.maxMagazineSize);
            targetscript.currentMagazineBullets = EditorGUILayout.IntField("Current Magazine Bullets", targetscript.currentMagazineBullets);
            targetscript.force    = EditorGUILayout.FloatField("ShotForce", targetscript.force);
            targetscript.Damage   = EditorGUILayout.FloatField("Bullet Damage", targetscript.Damage);
            targetscript.FireRate = EditorGUILayout.FloatField("Fire Rate", targetscript.FireRate);



            EditorGUILayout.LabelField("Weapon Info", EditorStyles.largeLabel);
            targetscript.WantsBurstFire = EditorGUILayout.Toggle("Wants Burst Fire", targetscript.WantsBurstFire);
            if (targetscript.WantsBurstFire == true)
            {
                targetscript.burstTime    = EditorGUILayout.FloatField("Time between bullets", targetscript.burstTime);
                targetscript.AmmountBurst = EditorGUILayout.IntField("Number of bullets", targetscript.AmmountBurst);
            }

            targetscript.WantsMaxSuppBullets = EditorGUILayout.Toggle("Wants Supp Bullets", targetscript.WantsMaxSuppBullets);


            if (targetscript.WantsMaxSuppBullets == true)
            {
                targetscript.maxSuppBullets     = EditorGUILayout.IntField("Ammo Max Supply", targetscript.maxSuppBullets);
                targetscript.currentSuppBullets = EditorGUILayout.IntField("Ammo Current Supply", targetscript.currentSuppBullets);
            }
            targetscript.wantSpecificAmmo = EditorGUILayout.Toggle("Specific Ammo", targetscript.wantSpecificAmmo);
            if (targetscript.wantSpecificAmmo == true)
            {
                targetscript.ammo = (AmmoType)EditorGUILayout.ObjectField("Ammo Type", targetscript.ammo, typeof(AmmoType), true);
            }
            //---------------------------------------------------------------------------------------------------------------------------------------------

            //---------------------------------------------------------------------------------------------------------------------------------------------

            targetscript.wantsRecoil = EditorGUILayout.Toggle("Wants Recoil", targetscript.wantsRecoil);


            if (targetscript.wantsRecoil == true)
            {
                targetscript.max_uprecoil          = EditorGUILayout.FloatField("Max Up Recoil", targetscript.max_uprecoil);
                targetscript.max_rightrecoil       = EditorGUILayout.FloatField("Max Right Recoil", targetscript.max_rightrecoil);
                targetscript.increment_uprecoil    = EditorGUILayout.FloatField("Increment Up Recoil", targetscript.increment_uprecoil);
                targetscript.increment_rightrecoil = EditorGUILayout.FloatField("Increment Right Recoil", targetscript.increment_rightrecoil);
                targetscript.decrement_recoil      = EditorGUILayout.FloatField("Decrement All Recoil", targetscript.decrement_recoil);
            }
            //---------------------------------------------------------------------------------------------------------------------------------------------


            if (GUILayout.Button("Save"))
            {
                Debug.Log("Save Button Pressed");
                serializedObject.ApplyModifiedProperties();
            }
            //DrawDefaultInspector();
        }
Пример #18
0
 // Start is called before the first frame update
 void Start()
 {
     Cursor.lockState = CursorLockMode.Locked;
     gb = Weapon.GetComponent <GunBehaviour>();
 }
Пример #19
0
 private void PlayerSwitchedGun(GunBehaviour gunBehaviour)
 {
     gun = gunBehaviour;
 }
Пример #20
0
	protected override void OnAwake ()
	{
		Gun = this;

		
	}
Пример #21
0
 void Start()
 {
     gun  = gunController.GetComponent <MachineGunBehaviour>();
     ammo = "Explosive";
 }
Пример #22
0
	void OnDestroy()
	{
		Gun = null;
	}