예제 #1
0
        private void Start()
        {
            isPlayerDead = false;

            playerRigidbody = GetComponent <Rigidbody>();
            controller      = GetComponent <FPSController>();
            playerCollider  = GetComponent <CapsuleCollider>();
            weaponManager   = FindObjectOfType <WeaponManager>();
            sway            = FindObjectOfType <Sway>();

            mainCameraGameobject = Camera.main.gameObject;
            mainCameraStartPos   = mainCameraGameobject.transform.position;
        }
예제 #2
0
        private void Start()
        {
            GetWeaponSettings();

            if (weaponType != WeaponType.Melee && weaponType != WeaponType.Grenade)
            {
                BalisticProjectilesPool();
            }

            if (GetComponent <Animator>())
            {
                animator = GetComponent <Animator>();
            }
            else
            {
                Debug.LogError("Please attach animator to your weapon object");
            }

            if (GetComponent <AudioSource>())
            {
                audioSource = GetComponentInParent <AudioSource>();
            }
            else
            {
                Debug.LogError("Please attach AudioSource to your weapon object");
            }

            cam = Camera.main;

            controller = FindObjectOfType <FPSController>();

            normalSensX = controller.sensitivity.x;
            normalSensY = controller.sensitivity.y;
            normalFOV   = cam.fieldOfView;

            weaponManager = FindObjectOfType <WeaponManager>();

            scope          = weaponManager.scopeImage;
            ammoText       = GameObject.Find("AmmoText").GetComponent <Text>();
            weaponNameText = GameObject.Find("WeaponText").GetComponent <Text>();

            recoilComponent = FindObjectOfType <Recoil>();
            sway            = FindObjectOfType <Sway>();

            if (weaponType != WeaponType.Melee && weaponType != WeaponType.Grenade)
            {
                if (shell)
                {
                    ShellsPool();
                }
                else
                {
                    Debug.LogError("No shell gameobject attached to weapon settings object");
                }

                if (MuzzleFlashParticlesFX)
                {
                    temp_MuzzleFlashParticlesFX = Instantiate(MuzzleFlashParticlesFX, muzzleFlashTransform.position, muzzleFlashTransform.rotation, muzzleFlashTransform);
                }
                else
                {
                    Debug.LogWarning("There is no shot particle system attached to weapon settings");
                }
            }

            hitFXManager = FindObjectOfType <HitFXManager>();

            ricochetSource = hitFXManager.gameObject.GetComponent <AudioSource>();
            ricochetSounds = hitFXManager.ricochetSounds;

            inventory = FindObjectOfType <Inventory>();
            input     = FindObjectOfType <InputManager>();

            if (weaponManager.UseNonPhysicalReticle)
            {
                if (GameObject.Find("StaticReticle") != null)
                {
                    staticReticle = GameObject.Find("StaticReticle");
                }
            }
            else
            {
                if (GameObject.Find("DynamicReticle") != null)
                {
                    dynamicReticle = GameObject.Find("DynamicReticle").GetComponent <RectTransform>();
                }
            }

            var item = new Item(ammoItemID, "ammo", "ammo", ItemType.ammo);

            item.ammo = 100;

            inventory.GiveItem(item);
        }
예제 #3
0
 private void OnEnable()
 {
     manager       = FindObjectOfType <WeaponManager>();
     swayTransform = FindObjectOfType <Sway>();
 }
        public void ON()
        {
            if (!once)
            {
                gm = GameObject.Find("GamePrefab").GetComponent <GameManager>();
                if (gm.InTutorial)
                {
                    enableShoot = false;
                }
                else
                {
                    enableShoot = true;
                }
                Sway swayObject = FindObjectOfType <Sway>();
                if (swayObject != null)
                {
                    swayTransform = FindObjectOfType <Sway>().GetComponent <Transform>();
                }

                if (swayTransform != null)
                {
                    for (int i = 0; i < slotsSize; i++)
                    {
                        Slot slot_temp = gameObject.AddComponent <Slot>();

                        slots.Add(slot_temp);
                    }

                    if (haveMeleeWeaponByDefault)
                    {
                        slots[0].storedWeapon = melleeDefaultWeapon;
                        activeSlot            = slots[0];
                    }
                    else
                    {
                        slots[indexSlot].storedWeapon = PrimaryGun;
                        activeSlot = slots[indexSlot];
                        slots[indexSlot].storedWeapon.currentAmmo = 0;
                        //AGREGO LAS ARMAS COMPRADAS EN LA TIENDA
                        if (gd.gameMode == GameData.GameMode.Survival)
                        {
                            M4.currentAmmo     = 30;
                            SCAR.currentAmmo   = 30;
                            Sniper.currentAmmo = 10;
                        }
                        if (gd.dataPlayer.unlockedM4 || gd.gameMode == GameData.GameMode.Survival)
                        {
                            indexSlot++;
                            if (indexSlot < slots.Count)
                            {
                                M4.currentAmmo = 30;
                                M4._totalAmmo  = gd.dataPlayer.M4Ammo;
                                slots[indexSlot].storedWeapon = M4;
                                indexM4 = indexSlot;
                            }
                        }
                        if (gd.dataPlayer.unlockedScar)
                        {
                            indexSlot++;
                            if (indexSlot < slots.Count)
                            {
                                SCAR.currentAmmo = 30;
                                SCAR._totalAmmo  = gd.dataPlayer.scarAmmo;
                                slots[indexSlot].storedWeapon = SCAR;
                            }
                        }
                        if (gd.dataPlayer.unlockedSniper)
                        {
                            indexSlot++;
                            if (indexSlot < slots.Count)
                            {
                                Sniper.currentAmmo            = 10;
                                Sniper._totalAmmo             = gd.dataPlayer.SniperAmmo;
                                slots[indexSlot].storedWeapon = Sniper;
                            }
                        }
                    }
                    if (enableGrenade)
                    {
                        if (grenade != null)
                        {
                            indexSlot++;
                            if (indexSlot < slots.Count)
                            {
                                slots[indexSlot].storedWeapon = grenade;
                            }
                        }
                    }

                    scopeImage.SetActive(false);

                    if (UseNonPhysicalReticle)
                    {
                        reticleStatic.SetActive(true);
                        reticleDynamic.SetActive(false);
                    }
                    else
                    {
                        reticleStatic.SetActive(false);
                        reticleDynamic.SetActive(true);
                    }

                    playerTransform = GameObject.FindGameObjectWithTag("Player").transform;

                    foreach (Weapon weapon in swayTransform.GetComponentsInChildren <Weapon>(true))
                    {
                        weapons.Add(weapon);
                    }

                    inventory       = FindObjectOfType <Inventory>();
                    switchSlotIndex = 0;
                    SlotChange();
                }
                once = true;
            }
        }