public void CallOnShoot()
 {
     if (OnShoot != null)
     {
         OnShoot.Invoke();
     }
 }
示例#2
0
    private void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");
        Axis       = new Vector2(horizontal, vertical);
        if (Input.GetKey(KeyCode.Q))
        {
            RotateDirection += 1;
        }
        else if (Input.GetKey(KeyCode.E))
        {
            RotateDirection += -1;
        }
        else
        {
            RotateDirection += 0;
        }



        if (Input.GetKey(KeyCode.Space))
        {
            if (OnShoot != null)
            {
                OnShoot.Invoke();
            }
        }
    }
示例#3
0
    private void Handleshooting()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 mousePosition = UtilsClass.GetMouseWorldPosition();

            ani.SetBool("shoot", true);
            OnShoot.Invoke(this, new OnShootEventArgs
            {
                gunEndPointPosition = aimGunEndPointTransform.position,
                shootPosition       = mousePosition,
            });
        }
        else
        {
            ani.SetBool("shoot", false);
        }
        if (Input.GetMouseButtonDown(1))
        {
            isAimDownSights = !isAimDownSights;
            if (isAimDownSights)
            {
                newfieldofview.SetFoV(40f);
                newfieldofview.SetViewDistance(100f);
            }
            else
            {
                newfieldofview.SetFoV(90f);
                newfieldofview.SetViewDistance(50f);
            }
        }
    }
示例#4
0
 public static void Shoot()
 {
     if (!PlayerProfile.sounds)
     {
         return;
     }
     OnShoot.Invoke();
 }
    private void ShootProjectile()
    {
        GameObject projectile = Instantiate(rangedEnemyCharacterData.projectilePrefab, transform.position, Quaternion.identity);

        projectile.GetComponent <BaseProjectile>().ShootProjectile(target.position, rangedEnemyCharacterData.projectileSpeed, rangedEnemyCharacterData.damageAmount, rangedEnemyCharacterData.accuracy);

        if (OnShoot != null)
        {
            OnShoot.Invoke();
        }
    }
示例#6
0
    private void Shoot()
    {
        if (OnShoot != null)
        {
            OnShoot.Invoke();
        }

        BulletScript _bullet = Instantiate(bullet, shootingPoint.position, Quaternion.identity);

        _bullet.gameObject.SetActive(true);
    }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        if (active)
        {
            anim.ResetTrigger("Shoot");
            aiming         = Input.GetMouseButton(1);
            sprinting      = !aiming && Input.GetButton("Sprint");
            speedModifier  = Input.GetMouseButton(1) ? aimModifier : (Input.GetButton("Sprint") ? sprintModifier : 1);
            movementVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            TranslateMovement(CameraForward(movementVector));

            if (aiming)
            {
                gun.localPosition = aimGun;
            }
            else
            {
                gun.localPosition = walkGun;
            }

            if (movementVector != Vector3.zero)
            {
                anim.SetFloat("IdleWalk", 1f);
                Footsteps();

                if (sprinting)
                {
                    anim.SetFloat("WalkSprint", 1f);
                }
                else
                {
                    anim.SetFloat("WalkSprint", 0f);
                }
            }
            else
            {
                anim.SetFloat("IdleWalk", 0f);
            }

            anim.SetBool("Aiming", aiming);

            if (Input.GetButtonDown("Fire1"))
            {
                if (OnShoot != null)
                {
                    OnShoot.Invoke();
                }
                anim.SetTrigger("Shoot");
            }
        }
    }
示例#8
0
    private void Shoot()
    {
        var      direction = Quaternion.EulerRotation(0, UnityEngine.Random.Range(-_spread, _spread), 0) * transform.forward;
        ShotData shotData  = new ShotData(direction * _bulletSpeed * (AvatarController.Inverted ? -1 : 1));

        var bullet = Instantiate(_bulletPrefab).GetComponent <Bullet>();

        bullet.transform.position = transform.position;
        bullet.Initialize(shotData);
        if (OnShoot != null)
        {
            OnShoot.Invoke(shotData);
        }
    }
示例#9
0
    public void AttackingEvent()
    {
        _attackCounter += Time.deltaTime;

        if (_attackCounter >= _attackSpeed)
        {
            _attackCounter = 0;

            if (EnemyGlobalListener.Instance.NearestEnemy != null)
            {
                OnShoot.Invoke();
            }
        }
    }
示例#10
0
        public static void InvokeOnShoot(ReferenceHub shooter, GameObject target, ref bool allow)
        {
            OnShoot onShoot = ShootEvent;

            if (onShoot == null)
            {
                return;
            }
            ShootEvent ev = new ShootEvent
            {
                Shooter = shooter,
                Allow   = allow,
                Target  = target
            };

            onShoot.Invoke(ref ev);
            allow = ev.Allow;
        }
示例#11
0
    private void Shoot(Vector3 target)
    {
        if (canShoot)
        {
            cork.useGravity = true;
            rope.ResetSegmentLength();

            cork.MovePosition(muzzle.position);
            Vector3 shootDirection = (target - muzzle.position).normalized;
            cork.AddForce(shootDirection * shootSpeed, ForceMode.VelocityChange);

            canShoot = false;

            OnShoot?.Invoke(this, new OnShootEventArgs
            {
                shootDirection = shootDirection
            });
        }
    }
示例#12
0
文件: Gun.cs 项目: TheOctan/ShotGun
        void Shoot()
        {
            if (!isReloading && Time.time > nextShotTime && projectilesRemaningInMag > 0)
            {
                if (fireMode == FireMode.Burst)
                {
                    if (shotsRemainingInBurst == 0)
                    {
                        return;
                    }
                    shotsRemainingInBurst--;
                }
                else if (fireMode == FireMode.Single)
                {
                    if (!triggerReleasedSinceLastShot)
                    {
                        return;
                    }
                }

                for (int i = 0; i < projectileSpawn.Length; i++)
                {
                    if (projectilesRemaningInMag == 0)
                    {
                        break;
                    }
                    projectilesRemaningInMag--;
                    nextShotTime = Time.time + msBetweenShots / 1000f;
                    Projectile newProjectile = Instantiate(projectile, projectileSpawn[i].position, projectileSpawn[i].rotation);
                    newProjectile.SetSpeed(muzzleVelocity);
                }

                Instantiate(shell, shellEjection.position, shellEjection.rotation);
                muzzleflash.Activate();
                transform.localPosition -= Vector3.forward * Random.Range(kickMinMax.x, kickMinMax.y);
                recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
                recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);

                AudioManager.instance.PlaySound(shootAudio, transform.position);
                OnShoot?.Invoke();
            }
        }
    private void HandleShooting()
    {
        if (Input.GetMouseButtonDown(0))
        {
            GameObject  bullet = Instantiate(bulletPrefab, bulletSpawnPos.position, transform.rotation);
            Rigidbody2D rb     = bullet.GetComponent <Rigidbody2D>();

            Vector3 mousePosition = cam.ScreenToWorldPoint(Input.mousePosition);

            aimAnim.SetTrigger("Shoot");

            OnShoot?.Invoke(this, new OnShootEventArgs
            {
                gunEndPointPosition = aimGunEndPointTransform.position,
                shootPosition       = mousePosition,
                shellPosition       = aimShellPosition.position,
            });

            rb.AddForce(bulletSpawnPos.right * bulletForce, ForceMode2D.Impulse);
            Destroy(bullet, 5f);
        }
    }
示例#14
0
    private void HandleShooting()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 mousePosition = UtilsClass.GetMouseWorldPosition();

            aimAnimator.SetTrigger("Shoot");
            GetComponents <AudioSource>()[0].PlayOneShot(shootClip);

            Vector3      aimDirection = (mousePosition - aimTransform.position).normalized;
            RaycastHit2D raycastHit2D = Physics2D.Raycast(aimGunEndPointTransform2.position, aimDirection);
            if (raycastHit2D.collider != null)
            {
                Enemy_simple enemy = raycastHit2D.collider.GetComponent <Enemy_simple>();
                if (enemy)
                {
                    enemy.Damage(100);



                    if (enemy.GetComponent <AudioSource>())
                    {
                        GetComponents <AudioSource>()[1].PlayOneShot(enemy.GetComponent <AudioSource>().clip);
                    }

                    Utils.MonsterKilled      += 1;
                    Utils.MonsterKilledTotal += 1;
                }
            }

            OnShoot?.Invoke(this, new OnShootEventArgs
            {
                gunEndPointPosition = aimGunEndPointTransform.position,
                shootPosition       = mousePosition,
                shellPosition       = aimShellPositionTransform.position,
            });
        }
    }
示例#15
0
    private void Update()
    {
        if (Vector2.Distance(target.transform.position, obj.transform.position) < 7f)
        {
            if (OnShoot != null)
            {
                OnShoot.Invoke();
            }
        }

        Vector3 vectorToTarget = target.transform.position - obj.transform.position;

        RotateDirection = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg - 90;

        if (Vector2.Distance(target.transform.position, obj.transform.position) < stopDistance)
        {
            Axis = Vector2.zero;
        }
        else
        {
            Axis = (target.transform.position - obj.transform.position).normalized;
        }
    }
    private void CharacterAimBase_OnShoot(object sender, CharacterAim_Base.OnShootEventArgs e)
    {
        Shoot_Flash.AddFlash(e.gunEndPointPosition);
        WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition);
        ShakeCamera(.6f, .05f);
        SpawnBulletShellCasing(e.gunEndPointPosition, e.shootPosition);

        if (weaponType == WeaponType.Shotgun)
        {
            // Shotgun spread
            int shotgunShells = 4;
            for (int i = 0; i < shotgunShells; i++)
            {
                WeaponTracer.Create(e.gunEndPointPosition, e.shootPosition + GetRandomDir() * UnityEngine.Random.Range(-20f, 20f));
                if (i % 2 == 0)
                {
                    SpawnBulletShellCasing(e.gunEndPointPosition, e.shootPosition);
                }
            }
        }

        // Any enemy hit?
        RaycastHit2D raycastHit = Physics2D.Raycast(e.gunEndPointPosition, (e.shootPosition - e.gunEndPointPosition).normalized, Vector3.Distance(e.gunEndPointPosition, e.shootPosition));

        if (raycastHit.collider != null)
        {
            EnemyHandler enemyHandler = raycastHit.collider.gameObject.GetComponent <EnemyHandler>();
            if (enemyHandler != null)
            {
                Debug.Log("Cannot Damage!");
                //enemyHandler.Damage(characterAimBase);
            }
        }

        OnShoot?.Invoke(this, e);
    }
    void Update()
    {
        m_cooldown.Update(Time.deltaTime);

        if (Input.GetMouseButton(0) && m_cooldown.IsOver())
        {
            RaycastHit hitInfo;
            var        ray    = Camera.main.ScreenPointToRay(Input.mousePosition);
            var        rayHit = Physics.Raycast(ray, out hitInfo);

            if (rayHit)
            {
                var bullet = global::Spawner.Spawn(m_bulletPrefab, Camera.main.ScreenToWorldPoint(Input.mousePosition));
                Debug.Assert(bullet.GetComponent <SpawnerExampleBullet>(), "Bullet should have a bullet component.");
                bullet.GetComponent <SpawnerExampleBullet>().Shoot(ray.direction * 10.0f);
                if (OnShoot != null)
                {
                    OnShoot.Invoke(new ShootEventData(gameObject));
                }

                m_cooldown.Start();
            }
        }
    }
示例#18
0
 public void Use()
 {
     _objectPool.Take(_transform.position, _transform.rotation);
     OnShoot?.Invoke(this, System.EventArgs.Empty);
 }
示例#19
0
 private void CharacterAimBase_OnShoot(object sender, CharacterAim_Base.OnShootEventArgs e)
 {
     OnShoot?.Invoke(this, e);
 }
示例#20
0
        public void ReadRequest(RequestMessageIDs id, PacketReader stream, NpcInst npc)
        {
            switch (id)
            {
            case RequestMessageIDs.JumpFwd:
                OnJump?.Invoke(npc, JumpMoves.Fwd);
                break;

            case RequestMessageIDs.JumpRun:
                OnJump?.Invoke(npc, JumpMoves.Run);
                break;

            case RequestMessageIDs.JumpUp:
                OnJump?.Invoke(npc, JumpMoves.Up);
                break;

            case RequestMessageIDs.ClimbHigh:
                OnClimb?.Invoke(npc, ClimbMoves.High, new NPC.ClimbingLedge(stream));
                break;

            case RequestMessageIDs.ClimbMid:
                OnClimb?.Invoke(npc, ClimbMoves.Mid, new NPC.ClimbingLedge(stream));
                break;

            case RequestMessageIDs.ClimbLow:
                OnClimb?.Invoke(npc, ClimbMoves.Low, new NPC.ClimbingLedge(stream));
                break;

            case RequestMessageIDs.DrawFists:
                OnDrawFists?.Invoke(npc);
                break;

            case RequestMessageIDs.DrawWeapon:
                OnDrawWeapon?.Invoke(npc, npc.Inventory.GetItem(stream.ReadByte()));
                break;

            case RequestMessageIDs.AttackForward:
                OnFightMove?.Invoke(npc, FightMoves.Fwd);
                break;

            case RequestMessageIDs.AttackLeft:
                OnFightMove?.Invoke(npc, FightMoves.Left);
                break;

            case RequestMessageIDs.AttackRight:
                OnFightMove?.Invoke(npc, FightMoves.Right);
                break;

            case RequestMessageIDs.AttackRun:
                OnFightMove?.Invoke(npc, FightMoves.Run);
                break;

            case RequestMessageIDs.Parry:
                OnFightMove?.Invoke(npc, FightMoves.Parry);
                break;

            case RequestMessageIDs.Dodge:
                OnFightMove?.Invoke(npc, FightMoves.Dodge);
                break;

            case RequestMessageIDs.DropItem:
                OnDropItem?.Invoke(npc, npc.Inventory.GetItem(stream.ReadByte()), stream.ReadUShort());
                break;

            case RequestMessageIDs.TakeItem:
                if (npc.World.TryGetVob(stream.ReadUShort(), out ItemInst item))
                {
                    OnTakeItem?.Invoke(npc, item);
                }
                break;

            case RequestMessageIDs.EquipItem:
                OnEquipItem?.Invoke(npc, npc.Inventory.GetItem(stream.ReadByte()));
                break;

            case RequestMessageIDs.UnequipItem:
                OnUnequipItem?.Invoke(npc, npc.Inventory.GetItem(stream.ReadByte()));
                break;

            case RequestMessageIDs.UseItem:
                OnUseItem?.Invoke(npc, npc.Inventory.GetItem(stream.ReadByte()));
                break;

            case RequestMessageIDs.Aim:
                OnAim?.Invoke(npc);
                break;

            case RequestMessageIDs.Unaim:
                OnUnaim?.Invoke(npc);
                break;

            case RequestMessageIDs.Shoot:
                OnShoot?.Invoke(npc, stream.ReadVec3f(), stream.ReadVec3f());
                break;

            case RequestMessageIDs.Voice:
                OnVoice?.Invoke(npc, (VoiceCmd)stream.ReadByte());
                break;

            case RequestMessageIDs.HelpUp:
                if (npc.World.TryGetVob(stream.ReadUShort(), out NpcInst target))
                {
                    OnHelpUp?.Invoke(npc, target);
                }
                break;

            default:
                GUC.Log.Logger.Log("Received Script RequestMessage with invalid ID: " + id.ToString());
                break;
            }
        }
示例#21
0
 public void MustShoot(int id)
 {
     OnShoot?.Invoke(id);
 }
示例#22
0
 public void EventShoot()
 {
     OnShoot?.Invoke();
 }
示例#23
0
 /// <summary>
 /// <para>Invokes the OnShoot event</para>
 /// </summary>
 public void Shoot()
 {
     OnShoot?.Invoke();
 }
示例#24
0
 public virtual void Shoot()
 {
     OnShoot?.Invoke(this);
 }
示例#25
0
 private void _OnShoot()
 {
     OnShoot?.Invoke(this, EventArgs.Empty);
 }
示例#26
0
 public void Shoot()
 {
     OnShoot.Invoke(chargeBar.chargePower);
     gameObject.SetActive(false);
 }
示例#27
0
    private void HandleShooting()
    {
        var mousePos = Input.mousePosition;

        mousePos.z = 10;
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(mousePos);
        Vector3 aimDirection  = (mousePosition - transform.position).normalized;
        float   angle         = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg;

        aimTransform.eulerAngles = new Vector3(0, 0, angle);

        Quaternion myAngle = new Quaternion(0, 0, angle, 0);

        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit2D hit = Physics2D.Linecast(aimGunEndPointTransform.position, mousePosition);

            if (hit.collider != null && hit.collider.tag == "PortalableSurface")
            {
                Vector2 portalPosition = hit.point;
                Debug.Log("Hit");
                Debug.Log(hit.fraction);
                Debug.DrawRay(aimGunEndPointTransform.position, aimDirection * hit.distance, Color.yellow);
                if (GameObject.Find("BluePortal(Clone)") != null)
                {
                    GameObject clone         = GameObject.Find("BluePortal(Clone)");
                    GameObject waypointClone = GameObject.Find("OrangeToBlueWaypoint(Clone)");
                    Destroy(clone.gameObject);
                    Destroy(waypointClone.gameObject);
                    GameObject BluePortalNew        = Instantiate(BluePortal, portalPosition, myAngle);
                    GameObject OrangeToBlueWayPoint = Instantiate(OrangeToBlueWaypoint, portalPosition, myAngle);
                    OrangeToBlueWayPoint.transform.parent = BluePortalNew.transform;
                }
                else
                {
                    GameObject BluePortalNew        = Instantiate(BluePortal, portalPosition, myAngle);
                    GameObject OrangeToBlueWayPoint = Instantiate(OrangeToBlueWaypoint, portalPosition, myAngle);
                    OrangeToBlueWayPoint.transform.parent = BluePortalNew.transform;
                }
            }



            aimAnimator.SetTrigger("Shoot");
            OnShoot?.Invoke(this, new OnShootEventArgs
            {
                gunEndPointPosition = aimGunEndPointTransform.position,
                shootPosition       = mousePosition,
            });
        }

        if (Input.GetMouseButtonDown(1))
        {
            Debug.Log("Shot");
            RaycastHit2D hit = Physics2D.Linecast(aimGunEndPointTransform.position, mousePosition);

            if (hit.collider != null && hit.collider.tag == "PortalableSurface")
            {
                Debug.Log("Hit");
                Vector2 portalPosition = hit.point;
                Debug.Log("Hit");
                Debug.Log(hit.fraction);
                Debug.DrawRay(aimGunEndPointTransform.position, aimDirection * hit.distance, Color.yellow);
                if (GameObject.Find("OrangePortal(Clone)") != null)
                {
                    GameObject clone         = GameObject.Find("OrangePortal(Clone)");
                    GameObject waypointClone = GameObject.Find("BlueToOrangeWaypoint(Clone)");
                    Destroy(clone.gameObject);
                    Destroy(waypointClone);
                    GameObject OrangePortalNew         = Instantiate(OrangePortal, portalPosition, myAngle);
                    GameObject NewBlueToOrangeWaypoint = Instantiate(BlueToOrangeWaypoint, portalPosition, myAngle);
                    NewBlueToOrangeWaypoint.transform.parent = OrangePortalNew.transform;
                }
                else
                {
                    GameObject OrangePortalNew         = Instantiate(OrangePortal, portalPosition, myAngle);
                    GameObject NewBlueToOrangeWaypoint = Instantiate(BlueToOrangeWaypoint, portalPosition, myAngle);
                    NewBlueToOrangeWaypoint.transform.parent = OrangePortalNew.transform;
                }
            }



            aimAnimator.SetTrigger("Shoot");
            OnShoot?.Invoke(this, new OnShootEventArgs
            {
                gunEndPointPosition = aimGunEndPointTransform.position,
                shootPosition       = mousePosition,
            });
        }
    }