public override void OnEnabled(Animator anim)
        {
            Events = new ThrowingEvents();
            TriggS = new LayersWithDefValue <SystemTrigger>(new ThrowSystemTriggers());

            transform    = userInput.transform;
            playerCamera = userInput.cameraRig.GetComponent <PlayerCamera>();
            animator     = transform.GetComponent <Animator>();

            foreach (Transform t in transform.GetComponentsInChildren <Transform>())
            {
                if (t.CompareTag("LeftHandHold"))
                {
                    leftHandHold = t.FindChild("PosRotFixer");
                }
                if (t.CompareTag("RightHandHold"))
                {
                    rightHandHold2 = t.FindChild("PosRotFixer2");
                }
            }

            foreach (Transform tr in userInput.cameraRig.GetComponentsInChildren <Transform>())
            {
                if (tr.CompareTag("Target"))
                {
                    refTarget = tr;
                }
            }
            if (userInput && userInput.cameraRig)
            {
                foreach (var trn in userInput.cameraRig.GetComponentsInChildren <Transform>())
                {
                    if (trn.name == "TurnTo Reference")
                    {
                        TurnToReference = trn;
                    }
                }
            }
            if (!rightHandHold2)
            {
                Debug.Log("PosRotFixer2 not found, mirrored throw wont work properly...");
            }
            if (!leftHandHold || !playerCamera || !animator)
            {
                userInput.DisablePlayer("Needed transform not found in " + ToString());
                return;
            }

            player.onIsHandOnBomb  += HandOnBomb;
            player.onIsHandOffBomb += HandOffBomb;

            player.throwableBag.RemoveAll(x => x.haveCount <= 0 || x.throwablePrefab == null);

            CurrentThrowableIndex = player.defaultThrowableIndex >= player.throwableBag.Count ? -1 : player.defaultThrowableIndex;
            if (GetStyleOfIndex(CurrentThrowableIndex) != -1)
            {
                SetThrowable(CurrentThrowableIndex);
            }
            nextThrowableIndex = CurrentThrowableIndex;
        }
Exemple #2
0
        public override void OnEnabled(Animator anim)
        {
            if (userInput.transform.FindChild("CoverChecker"))
            {
                coverChecker = player.transform.FindChild("CoverChecker").GetComponent <CoverTargetLogic>();
            }
            animator  = userInput.GetComponent <Animator>();
            transform = userInput.transform;
            if (userInput.cameraRig)
            {
                moveReference = userInput.cameraRig.FindChild("Move Reference");
                playerCamera  = userInput.cameraRig.GetComponent <PlayerCamera>();
            }

            foreach (Transform tr in userInput.cameraRig.GetComponentsInChildren <Transform>())
            {
                if (tr.CompareTag("Target"))
                {
                    RefTarget = tr;
                }
            }

            Events = new CoveringEvents();

            if (!coverChecker || !animator || !transform || !moveReference || !RefTarget || !playerCamera || player.defaultCoverStyleIndex >= player.coverStyles.Count)
            {
                userInput.DisablePlayer("Reference not found on :" + ToString());
            }

            TriggS = new LayersWithDefValue <SystemTrigger>(new CoverSystemTriggers());

            LayerWeightTarget = 0;
        }
 private void Loaded()
 {
     playerCamera        = GetComponent <PlayerCamera>();
     gameManager         = FindObjectOfType <GameManager>();
     checkpointManager   = FindObjectOfType <CheckpointManager>();
     characterController = GetComponent <CharacterController>();
     isLoaded            = true;
 }
        public void FaceToMouse()
        {
            Vector2 screenPos = PlayerCamera.WorldToScreenPoint(Transform.position);
            Vector2 mousePos  = Input.mousePosition;
            Vector3 direction = new Vector3(mousePos.x - screenPos.x, 0, mousePos.y - screenPos.y);

            direction         = PlayerCamera.transform.TransformDirection(direction);
            direction.y       = 0;
            Transform.forward = direction.normalized;
        }
Exemple #5
0
    public void Fire(Player.PlayerCamera camera)
    {
        //AnimationController.SetBool("isReloading", Reloading == null);

        if (Reloading != null)
        {
            return;
        }

        if (currentShootingInterval >= 1 / roundsPerSecond)
        {
            //AnimationController.SetTrigger("Shoot");

            currentShootingInterval = 0f;
            CurrentMagazineSize    -= 1;

            if (ShootingSound != null)
            {
                ShootingSound.Play();
            }

            if (muzzleFlash != null)
            {
                muzzleFlash.Play();
            }



            Vector3 DesiredDestination = camera.Reticle.transform.position;
            Ray     ray = camera.GetCamera().ScreenPointToRay(camera.Reticle.transform.position);
            ray.direction += camera.GetCamera().transform.TransformDirection(Random.insideUnitCircle * spreadRadius / 10);

            RaycastHit info;
            if (Physics.Raycast(ray, out info, maxShootingRange))
            {
                if (impact != null)
                {
                    GameObject.Instantiate(impact, info.point, Quaternion.LookRotation(transform.forward * -1));
                }

                if (info.transform.GetComponent <Targetable>() != null)
                {
                    //Add dynamic damagage here
                    int Damage = showDynamicDamage == false ? damage : Random.Range(damage, dynamicDamage);
                    ;                   info.transform.GetComponent <Targetable>().ReceiveDamage(this, new DamageEventArgs(Damage));
                }
            }
        }

        if (CurrentMagazineSize <= 0)
        {
            Reload();
        }
    }
        void Awake()
        {
            if (camera == null)
            {
                camera = Camera.main.GetComponent <PlayerCamera>();
            }

            cameraFound = (camera != null);

            if (cameraFound)
            {
                camera.SyncStart();
            }
        }
Exemple #7
0
        public virtual void Init(bool attacking)
        {
            this._isAttacking = attacking;

            if (attacking)
            {
                this._uiComponent.Display();
                this._state = PlayerState.ATTACKING;
            }
            else
            {
                this._uiComponent.Hide();
                this._state = PlayerState.DEFENDING;
            }

            this._selectionState  = SelectionState.FREE;
            this._playerCamera    = PlayerCamera.CreateCamera(this, this._spawnLocation, attacking);
            this._playerSelection = this.playerCamera.gameObject.GetComponent <PlayerSelect>();
        }
Exemple #8
0
        private void Start()
        {
            toPrintThrowableCount = "00";
            toPrintCurrentClip    = "00";
            toPrintTotalAmmo      = "000";
            toPrintSecCurrentClip = "00";
            toPrintSecTotalAmmo   = "000";

            infoTexts      = new List <Small3dHudInfoText>();
            worldInfoTexts = new List <Small3dHudInfoText>();

            if (GameObject.FindGameObjectWithTag("Player"))
            {
                player    = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerAtts>();
                smbWeapon = player.SmbWeapon;
                smbWeapon.Events.onWeaponFire    += OnFire;
                smbWeapon.Events.onReloadDone    += OnReload;
                smbWeapon.Events.onWeaponPullOut += OnWeaponPullOut;
                smbWeapon.Events.onWeaponSwitch  += OnWeaponChange;
                smbWeapon.Events.onDropWeapon    += OnWeaponChange;
                smbWeapon.Events.onWeaponCollect += OnWeaponCollect;
                smbWeapon.Events.onSupplyCollect += SetAllCounts;

                player.SmbThrow.Events.onSwitch        += OnThrowableSwitch;
                player.SmbThrow.Events.onThrowableExit += OnThrowableExit;
            }

            if (!player)
            {
                Debug.Log("Needed reference not found..." + ToString());
                gameObject.SetActive(false);

                return;
            }
            playerCamera = player.GetComponent <SetupAndUserInput>().cameraRig.GetComponent <PlayerCamera>();

            foreach (var catcher in gameObject.GetComponentsInChildren <HudEventCatcher>())
            {
                catcher.onZeroAlphaTotalAmmo       += AnimEventOnTotalAmmoZeroAlpha;
                catcher.onZeroAlphaCurrentClipAmmo += AnimEventOnCurrentAmmoZeroAlpha;
            }

            foreach (var trns in transform.GetComponentsInChildren <Transform>())
            {
                if (trns.name == "Current Clip Capacity")
                {
                    cClipAnimator = trns.GetComponent <Animator>();
                }
                else if (trns.name == "Total Ammo")
                {
                    tAmmoAnimator = trns.GetComponent <Animator>();
                }
                else if (trns.name == "SecCurrent Clip Capacity")
                {
                    secCClipAnimator = trns.GetComponent <Animator>();
                }
                else if (trns.name == "SecTotal Ammo")
                {
                    secTAmmoAnimator = trns.GetComponent <Animator>();
                }
                else if (trns.name == "Weapon Image")
                {
                    weaponImage = trns.GetComponent <Image>();
                }
                else if (trns.name == "Weapon Name")
                {
                    weaponName = trns.GetComponent <Text>();
                }
                else if (trns.name == "Projectile Image")
                {
                    bulletImage = trns.GetComponent <Image>();
                }
                else if (trns.name == "Projectile Name")
                {
                    bulletName = trns.GetComponent <Text>();
                }
                else if (trns.name == "SecProjectile Image")
                {
                    secBulletImage = trns.GetComponent <Image>();
                }
                else if (trns.name == "SecProjectile Name")
                {
                    secBulletName = trns.GetComponent <Text>();
                }
                else if (trns.name == "Throwable Count")
                {
                    throwableCountAnimator = trns.GetComponent <Animator>();
                }
                else if (trns.name == "Throwable Name")
                {
                    throwableName = trns.GetComponent <Text>();
                }
                else if (trns.name == "Throwable Image")
                {
                    throwableImage = trns.GetComponent <Image>();
                }
                else if (trns.name == "InfoTextParentPanel")
                {
                    infoTextParentPanel = trns;
                }
            }

            foreach (var trns in cClipAnimator.GetComponentsInChildren <Transform>())
            {
                if (trns.name == "Text0")
                {
                    currentClipText0 = trns.GetComponent <Text>();
                }
                else if (trns.name == "Text1")
                {
                    currentClipText1 = trns.GetComponent <Text>();
                }
            }

            foreach (var trns in tAmmoAnimator.GetComponentsInChildren <Transform>())
            {
                if (trns.name == "Text0")
                {
                    totalAmmoText0 = trns.GetComponent <Text>();
                }
                else if (trns.name == "Text1")
                {
                    totalAmmoText1 = trns.GetComponent <Text>();
                }
                else if (trns.name == "Text2")
                {
                    totalAmmoText2 = trns.GetComponent <Text>();
                }
            }
            if (secCClipAnimator)
            {
                foreach (var trns in secCClipAnimator.GetComponentsInChildren <Transform>())
                {
                    if (trns.name == "Text0")
                    {
                        secCurrentClipText0 = trns.GetComponent <Text>();
                    }
                    else if (trns.name == "Text1")
                    {
                        secCurrentClipText1 = trns.GetComponent <Text>();
                    }
                }
            }
            if (secTAmmoAnimator)
            {
                foreach (var trns in secTAmmoAnimator.GetComponentsInChildren <Transform>())
                {
                    if (trns.name == "Text0")
                    {
                        secTotalAmmoText0 = trns.GetComponent <Text>();
                    }
                    else if (trns.name == "Text1")
                    {
                        secTotalAmmoText1 = trns.GetComponent <Text>();
                    }
                    else if (trns.name == "Text2")
                    {
                        secTotalAmmoText2 = trns.GetComponent <Text>();
                    }
                }
            }

            foreach (var trns in throwableCountAnimator.GetComponentsInChildren <Transform>())
            {
                if (trns.name == "Text0")
                {
                    throwableCountText0 = trns.GetComponent <Text>();
                }
                else if (trns.name == "Text1")
                {
                    throwableCountText1 = trns.GetComponent <Text>();
                }
            }

            currentClipText0.text = "0";
            currentClipText1.text = "0";

            totalAmmoText0.text = "0";
            totalAmmoText1.text = "0";
            totalAmmoText2.text = "0";

            if (secCurrentClipText0)
            {
                secCurrentClipText0.text = "0";
            }
            if (secCurrentClipText0)
            {
                secCurrentClipText1.text = "0";
            }

            if (secTotalAmmoText0)
            {
                secTotalAmmoText0.text = "0";
            }
            if (secTotalAmmoText1)
            {
                secTotalAmmoText1.text = "0";
            }
            if (secTotalAmmoText2)
            {
                secTotalAmmoText2.text = "0";
            }

            throwableCountText0.text = "0";
            throwableCountText1.text = "1";

            SetWeaponImage(player.SmbWeapon.GetCurrentWeaponSprite());
            SetWeaponName(player.SmbWeapon.GetCurrentWeaponName());
            SetBulletImage(player.SmbWeapon.GetCurrentBulletSprite());
            SetBulletnName(player.SmbWeapon.GetCurrentBulletName());
            SetSecBulletImage(player.SmbWeapon.GetSecCurrentBulletSprite());
            SetSecBulletnName(player.SmbWeapon.GetSecCurrentBulletName());

            CClipTexter(player.SmbWeapon.GetCurrentClip());
            TotalClipTexter(player.SmbWeapon.GetTotalAmmoCount());
            SecCClipTexter(player.SmbWeapon.GetSecCurrentClip());
            SecTotalClipTexter(player.SmbWeapon.GetSecTotalAmmoCount());

            SetThrowableImage(player.SmbThrow.GetThrowableSprite());
            SetThrowableName(player.SmbThrow.GetThrowableName());
            ThrowableCountTexter(player.SmbThrow.GetThrowableCount());

            followBone = player.GetComponent <Animator>().GetBoneTransform(bone);
        }