Ejemplo n.º 1
0
 void Awake()
 {
     _boxCollider    = GetComponent <BoxCollider2D>();
     _circleCollider = GetComponent <CircleCollider2D>();
     _myShooter      = GetComponent <WeaponShooter>();
     _myRidigbody2D  = GetComponent <Rigidbody2D>();
     _myHealth       = GetComponent <HealthHaver>();
     _myHealth.Died += HandleDied;
 }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     init();
     gameObject.tag = "Enemy";
     animator       = this.gameObject.GetComponent <Animator>();
     setAnimatorFalse();
     weapon = GetComponentInChildren <WeaponShooter>();
     agent  = GetComponent <NavMeshAgent>();
 }
Ejemplo n.º 3
0
 void Start()
 {
     _health       = GetComponent <HealthHaver>();
     _damageTaker  = GetComponent <PlayerDamageTaker>();
     _mover        = GetComponent <PlayerMover>();
     _shooter      = GetComponent <WeaponShooter>();
     _health.Died += StartSpawnEffect;
     StartSpawnEffect();
 }
Ejemplo n.º 4
0
 void weapondrop()
 {
     if (leftWeapon && OVRInput.Get(OVRInput.Button.Two, OVRInput.Controller.LTouch))
     {
         leftWeapon = null;
     }
     if (rightWeapon && OVRInput.Get(OVRInput.Button.Two, OVRInput.Controller.RTouch))
     {
         rightWeapon = null;
     }
 }
Ejemplo n.º 5
0
 public void childTrigger(Collider other)
 {
     if (other.gameObject.tag == "Weapon")
     {
         float leftDist  = Vector3.Distance(leftHandAnchor.position, other.transform.position);
         float rightDist = Vector3.Distance(rightHandAnchor.position, other.transform.position);
         if ((!leftWeapon) && OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.LTouch) && leftDist < 0.3)
         {
             if ((!rightWeapon) || (other.gameObject != rightWeapon.gameObject))
             {
                 leftWeapon = other.gameObject.GetComponent <WeaponShooter>();
             }
         }
         else if ((!rightWeapon) && OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.RTouch) && rightDist < 0.3)
         {
             if ((!leftWeapon) || (other.gameObject != leftWeapon.gameObject))
             {
                 rightWeapon = other.gameObject.GetComponent <WeaponShooter>();
             }
         }
     }
 }
Ejemplo n.º 6
0
 // Use this for initialization
 void Start()
 {
     weapon = GetComponent <WeaponShooter>();
     //muzzle = this.transform.Find("turret_muzzle").gameObject;
 }
Ejemplo n.º 7
0
 public void SetCombatWeapon(Weapon weapon)
 {
     _weapon        = weapon;
     _weaponShooter = weapon.WeaponShooter;
     UIController.instance.UpdateAmmoUI(_weaponShooter.CurrentAmmoInStore, _weaponShooter.CurrentAmmoAmmount);
 }
Ejemplo n.º 8
0
    /// <summary>
    /// simulates a melee swing by carrying out a sequence of
    /// timers, state changes and soft forces on the weapon springs
    /// </summary>
    protected void UpdateAttack()
    {
        if (!Player.Attack.Active)
        {
            return;
        }

        if (Player.SetWeapon.Active)
        {
            return;
        }

        if (FPWeapon == null)
        {
            return;
        }

        if (!FPWeapon.Wielded)
        {
            return;
        }

        if (Time.time < m_NextAllowedSwingTime)
        {
            return;
        }

        m_NextAllowedSwingTime = Time.time + SwingRate;

        // enable random attack states on the melee and weapon components
        if (AttackPickRandomState)
        {
            PickAttack();
        }

        // set 'raise' state (of the chosen attack state) on the weapon component
        FPWeapon.SetState(WeaponStatePull);
        FPWeapon.Refresh();

        // after a short delay, swing the weapon
        vp_Timer.In(SwingDelay, delegate()
        {
            // play a random swing sound
            if (SoundSwing.Count > 0)
            {
                Audio.pitch = Random.Range(SoundSwingPitch.x, SoundSwingPitch.y) * Time.timeScale;
                Audio.clip  = (AudioClip)SoundSwing[(int)Random.Range(0, (SoundSwing.Count))];
                if (vp_Utility.IsActive(gameObject))
                {
                    Audio.Play();
                }
            }

            // switch to the swing state
            FPWeapon.SetState(WeaponStatePull, false);
            FPWeapon.SetState(WeaponStateSwing);
            FPWeapon.Refresh();

            // apply soft forces of the current attack
            FPWeapon.AddSoftForce(SwingPositionSoftForce, SwingRotationSoftForce, SwingSoftForceFrames);

            // check for target impact after a predetermined duration
            vp_Timer.In(ImpactTime, delegate()
            {
                // perform a sphere cast ray from center of controller, at height
                // of camera and along camera angle
                RaycastHit hit;
                Ray ray = new Ray(new Vector3(FPController.Transform.position.x, FPCamera.Transform.position.y,
                                              FPController.Transform.position.z), FPCamera.Transform.forward);

                Physics.Raycast(ray, out hit, (Bullet != null ? Bullet.Range : 2), vp_Layer.Mask.BulletBlockers);

                // hit something: perform impact functionality
                if (hit.collider != null)
                {
                    if (WeaponShooter != null)
                    {
                        WeaponShooter.FirePosition = Camera.main.transform.position;
                        WeaponShooter.TryFire();
                    }
                    ApplyRecoil();
                }
                else
                {
                    // didn't hit anything: carry on swinging until time is up
                    vp_Timer.In(SwingDuration - ImpactTime, delegate()
                    {
                        FPWeapon.StopSprings();
                        Reset();
                    }, SwingDurationTimer);
                }
            }, ImpactTimer);
        }, SwingDelayTimer);
    }