示例#1
0
        void FireAmmunition(IShootable ammu, float speed = DEFAULT_AMMU_SPEED)
        {
            Vector3 direction = m_bulletSpawnTransform.up;

            direction = (direction * speed) + m_rb.velocity;
            ammu.Fire(m_rb.position, m_rb.rotation, direction);
        }
示例#2
0
        void HandleShooting(bool aiming)
        {
            RaycastHit hit;

            float actualSpread = currentSpread;

            if (aiming)
            {
                actualSpread *= .02f;
            }

            Vector3 randPos     = Random.insideUnitCircle * currentSpread;
            Vector3 shootOrigin = gunParent.position + gunParent.TransformDirection(randPos);
            Ray     ray         = new Ray(shootOrigin, gunParent.forward);

            if (Physics.Raycast(ray, out hit, 100))
            {
                IShootable shootable = hit.transform.GetComponent <IShootable>();
                if (shootable != null)
                {
                    shootable.OnHit(hit.point, gunParent.forward);
                }

                impactFx.SetActive(false);
                impactFx.transform.position = hit.point;
                impactFx.transform.LookAt(shootOrigin);
                impactFx.SetActive(true);
            }

            currentSpread += currentWeapon.spreadValue;
        }
示例#3
0
文件: Bullet.cs 项目: nwam/huntresses
    private void OnHit(GameObject other)
    {
        IShootable shootable = other.GetComponent <IShootable>();

        if (shootable != null)
        {
            // Hit an enemy
            shootable.GetShot(damage);
            animator.SetBool("bleed", true);

            if (followObj != null)
            {
                Vector3 offset = transform.position - other.transform.position;
                followObj.SetOffset(offset);
                followObj.SetTarget(other.transform);
                followObj.Enable();
            }
        }
        else
        {
            // Hit something other than an enemy
            // Walls, doors, etc.
            // In this case the animation is stationary
            animator.SetBool("spark", true);
        }
    }
示例#4
0
 void Awake()
 {
     health           = MAX_HEALTH;
     currentWeapon    = GetComponentInChildren <IShootable>();
     Rigidbody        = GetComponent <Rigidbody>();
     damagedCallback += DamageCallback;
 }
示例#5
0
        void OnTriggerEnter(Collider trigger)
        {
            IShootable ammu = trigger.gameObject.GetComponent <IShootable>();

            //	Ignore if is not a shot
            if (ammu == null)
            {
                return;
            }

            if (trigger.gameObject.tag != Tags.SaucerAmmu)
            {
                return;
            }

            Debug.Log(this.name + " -Trigger in " + trigger.gameObject.name);

            EnemyUnit sourceEntity       = ammu.Source.gameObject.GetComponentInParent <EnemyUnit>();      // Who Shoots?
            CollisionDetectedEventArgs e = new CollisionDetectedEventArgs();

            e.EnemyUnit = sourceEntity;

            OnPlayerGetsShot(this, e);

            /*CollisionDetectedEventArgs e = new CollisionDetectedEventArgs();
             * e.EnemyUnit = gameObject.GetComponent<EnemyUnit>();
             * OnPlayerGetsShot(this, e);*/
        }
示例#6
0
文件: Gun.cs 项目: fourls/red-inside
    public override void OnUse()
    {
        if (cooldown > 0)
        {
            return;
        }
        cooldown = cooldownTime;

        Vector2 targetPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        Vector2 direction = (targetPoint - (Vector2)barrel.position).normalized;

        if (Vector2.Dot(direction, Vector2.right * transform.localScale.x) <= maxDot)
        {
            return;
        }

        triggerCollider.enabled = false;
        RaycastHit2D hit = Physics2D.Raycast((Vector2)barrel.position, direction, 50f, GameManager.ins.shootableLayers);

        triggerCollider.enabled = true;

        if (hit.collider != null)
        {
            ShowGunLine(hit.point);

            IShootable shotObject = hit.collider.gameObject.GetComponent <IShootable>();
            if (shotObject != null)
            {
                shotObject.OnShot();
            }
        }
    }
示例#7
0
 private void Awake()
 {
     //Get all the interfaces the input will be interacting with
     movable   = GetComponent <IMovable>();
     rotable   = GetComponent <IRotable>();
     shootable = GetComponent <IShootable>();
 }
示例#8
0
 public void ArcherAtack(IShootable shootable)
 {
     if (TargetProviderGetter.HasTarget)
     {
         shootable.Shoot(TargetProviderGetter.GetTarget(), PrefabProvideGetter.GetPrefab(Arrow));
     }
 }
示例#9
0
        private void ProcessShoot()
        {
            if (InputManager.Controller.IsTapDown)
            {
                var point    = Camera.main.ScreenToWorldPoint(InputManager.Controller.TouchPosition);
                var collider = Physics2D.OverlapPoint(point, shootInteractionLayers);

                if (collider != null)
                {
                    IShootable shootable = collider.transform.GetComponent <IShootable>();

                    if (shootable != null)
                    {
                        shootable.OnShooted();

                        IScoresHolder scoresHolder = collider.transform.GetComponent <IScoresHolder>();

                        if (scoresHolder != null)
                        {
                            Main.SceneController.AddScores(scoresHolder.Scores);
                        }
                    }
                }
            }
        }
示例#10
0
    // Handle code for firing
    private void Shoot()
    {
        // Origin point for the raycast is center of the camera (TODO why is this not just camera.transform?)
        Vector3 origin = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

        // Raycast forward from camera origin, within user-set gun range
        if (Physics.Raycast(origin, cam.transform.forward, out RaycastHit hit, range))
        {
            // Try to find a receptor or pillar component (interfaced through IShootable) on the object that was hit
            IShootable hitObject = hit.collider.GetComponent <IShootable>();

            // If hit pillar, fill the gun container
            if (hitObject is Pillar pillar)
            {
                FillContainer(pillar);
            }
            // If hit receptor, empty the container
            else if (hitObject is ReceptorRing recp)
            {
                // Use timeout to register a click only once (instead of firing multiple colors after one another)
                if (!(timeSinceLastEmpty < _emptyingTimeout))
                {
                    if (Math.Abs(containerFill - 1) < .01 && colorInContainer.HasValue && recp.Hit(colorInContainer.Value))
                    {
                        EmptyContainer();
                    }
                }
            }
        }
    }
示例#11
0
    private void Shoot()
    {
        muzzleFlash.Play();
        audioMedic.pitch = Mathf.Max(Time.timeScale, .1f);
        audioMedic.Play();

        if (Time.timeScale > .9f)
        {
            RaycastHit hit;
            if (Physics.Raycast(_camera.transform.position, _camera.transform.forward, out hit, range))
            {
                Debug.Log(hit.transform.name);

                GameObject flashGO = Instantiate(flash, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(flashGO, 3f);

                IShootable shootable = hit.transform.GetComponent <IShootable>();
                if (shootable != null)
                {
                    shootable.OnShot();
                }
            }
        }
        else
        {
            GameObject ob = Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
            ob.SetActive(true);
        }
    }
示例#12
0
    void Shoot()
    {
        timer = 0f;

        gunLight.enabled = true;

        gunLine.enabled = true;
        gunLine.SetPosition(0, GunPoint.transform.position);

        shootRay.origin    = GunPoint.transform.position;
        shootRay.direction = GunPoint.transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            IShootable taker = shootHit.collider.GetComponent <IShootable> ();

            if (taker != null)
            {
                taker.TakeDamage(damagePerShot, shootHit.point);
            }

            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
示例#13
0
    protected override void Shoot()
    {
        gunLine.SetVertexCount(base.ShotsAtOnce * 2);

        gunLine.enabled  = true;
        gunLight.enabled = true;

        int j = 0;

        for (int i = 0; i < base.ShotsAtOnce; i++)
        {
            gunLine.SetPosition(j, base.WeaponEnd.position);
            j++;
            shootRay.origin    = base.WeaponEnd.position;
            shootRay.direction = new Vector3(base.WeaponEnd.forward.x + Random.Range(-base.Inaccuracy, base.Inaccuracy), base.WeaponEnd.forward.y, base.WeaponEnd.forward.z + Random.Range(-base.Inaccuracy, base.Inaccuracy));

            if (Physics.Raycast(shootRay, out shootHit, base.Range, shootableMask))
            {
                victim = shootHit.collider.gameObject;
                IShootable shootable = victim.GetComponent <IShootable> ();
                if (shootable != null)
                {
                    shootable.TakeDamage(base.DamagePerShot, shootHit.point);
                }
                gunLine.SetPosition(j, shootHit.point);
            }
            else
            {
                gunLine.SetPosition(j, shootRay.origin + shootRay.direction * base.Range);
            }
            j++;
        }
    }
示例#14
0
    public GameObject Shoot(float fireRate, GameObject from, float damage)
    {
        if (Ammo > 0)
        {
            Ammo--;
            RaycastHit hit;
            Ray        shootRay = new Ray(transform.position, -transform.forward);
            if (Physics.Raycast(shootRay, out hit, 500, shootableMask))
            {
                lineRenderer.SetPosition(0, shootPoint.position);

                lineRenderer.SetPosition(1, new Vector3(hit.point.x, shootPoint.position.y, hit.point.z));
                StartCoroutine(FireEffect(fireRate));

                MonoBehaviour[] mono = hit.collider.gameObject.GetComponents <MonoBehaviour>();
                foreach (MonoBehaviour m in mono)
                {
                    if (m is IShootable)
                    {
                        IShootable shootable = (IShootable)m;
                        shootable.OnGetShot(from, damage);
                    }
                }

                return(hit.collider.gameObject);
            }
        }

        return(null);
    }
示例#15
0
    // Start is called before the first frame update
    void Start()
    {
        audioSource = GetComponent <AudioSource>();

        if (health <= 0)
        {
            health = 1;
            Debug.LogError("Health set to 0 or less!");
        }

        maxHealth = health;
        guns      = new List <IShootable>();

        for (int i = 0; i < weapons.Count; i++)
        {
            IShootable g = weapons[i].GetComponent <IShootable>();
            if (g != null)
            {
                guns.Add(g);
            }
            if (i != currentWeapon)
            {
                g.HideWeapon();
            }
        }
        // Get Rigidbody
        rb  = GetComponent <Rigidbody>();
        cam = GetComponentInChildren <Camera>();
        // Hide mouse
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible   = false;
    }
示例#16
0
        void Update()
        {
            if (stopShooting)
            {
                return;
            }

            if (Time.time > m_nextFire)
            {
                m_nextFire = Time.time + fireRate;

                //	Check the direction between target and bulletSpawn point
                Vector3 direction = (target.position - bulletSpawnPoint.position).normalized;
                //	Calculate the angle determined by direction axis. Convert to Degrees
                float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg - 90;
                //	Rotates angle degrees around Z axis
                Quaternion qRotation = Quaternion.AngleAxis(angle, Vector3.forward);

                //	Instance ammunition to shoot (from pool)
                var ammunitionClone = PoolManager.SpawnObject(ammunitionPrefab);
                var ammuTransform   = ammunitionClone.transform;
                //	Set the ammu position/rotation accordingly
                ammuTransform.position = bulletSpawnPoint.position;
                ammuTransform.rotation = qRotation;

                //	Shoot and Play SFX
                IShootable shootable = ammunitionClone.GetComponent <IShootable>();
                shootable.Source = bulletSpawnPoint;

                AudioManager.Instance.PlaySFX(soundFXType);

                FireAmmunition(shootable, direction, shootSpeed == 0?DEFAULT_AMMU_SPEED:shootSpeed);
            }
        }
        //	Player Shot

        /*public event EventHandler<CollisionDetectedEventArgs> PlayerShot;
         * protected virtual void OnPlayerShot(object sender, CollisionDetectedEventArgs e)
         * {
         *      if (PlayerShot != null)
         *              PlayerShot(this, e);
         * }*/

        //	Active or Passive Enemy (Asteroids/Saucer) gets shot
        void OnTriggerEnter(Collider trigger)
        {
            IShootable ammu = trigger.gameObject.GetComponent <IShootable>();

            //	Ignore if is not a shot
            if (ammu == null)
            {
                return;
            }

            Transform       ammuSource   = ammu.Source;
            EntityBehaviour sourceEntity = ammuSource.gameObject.GetComponentInParent <EntityBehaviour>();
            EnemyUnit       targetUnit   = gameObject.GetComponentInParent <EnemyUnit>();

            if (targetUnit != null && sourceEntity != null)
            {
                /*if (targetUnit.tag == "Saucer")
                 *      Debug.Log("STOP");
                 *
                 * if (targetUnit.tag == "Player")
                 *      Debug.Log("PLAYER SHOT");
                 */

                // Unit Shot by Player (Asteroid or Saucer)
                CollisionDetectedEventArgs colisionEvent = new CollisionDetectedEventArgs();
                colisionEvent.SourceEntity = sourceEntity;                      //	Player
                colisionEvent.EnemyUnit    = targetUnit;                        //	Enemy Shot - Asteroid/Saucer

                //	Debug.Log(this.name + " -Trigger in " + trigger.gameObject.name);
                OnUnitShot(this, colisionEvent);
            }
        }
示例#18
0
    void Awake()
    {
        movable      = GetComponent <IMovable>();
        shootable    = GetComponentInChildren <IShootable>();
        destructible = GetComponent <Destructible>();

        player = FindObjectOfType <Player>();
    }
示例#19
0
 void Awake()          // когда игрок движется, линия рисуется не из ствола(
 //gunParticles = GetComponent<ParticleSystem>();
 //gunAudio = GetComponent<AudioSource>();
 {
     shootable       = gameObject.GetComponent <IShootable> ();
     gunLight        = GetComponentInChildren <Light> ();
     CurrentClipSize = MaxClipSize;
 }
示例#20
0
        private void OnTriggerExit(Collider other)
        {
            IShootable shoot = other.GetComponentInParent <IShootable>();

            shoot.OnHit(other.gameObject.transform.position);

            Invoke("DestroyBullet", 5f);
        }
示例#21
0
    void Awake()
    {
        // Initialize references between objects
        tankCtrl   = GetComponent <IMovable <sbyte> > ();
        turretCtrl = GetComponent <IRotatable> ();
        weaponCtrl = GetComponent <IShootable> ();

        //NetworkServer.Spawn (tankCtrl.gameObject);
    }
示例#22
0
    void DetectionSystem_OnTargetStatusChanged(GameObject target, bool found)
    {
        IShootable shootable = target.GetComponent <IShootable> ();

        if (shootable != null)
        {
            UpdateTargetStatus(shootable, found);
        }
    }
示例#23
0
 /// <summary>
 /// Sets the target and starts shooting if it is not null.
 /// </summary>
 /// <param name="newTarget">New target.</param>
 public void SetTarget(IShootable newTarget)
 {
     target = newTarget;
     if (target != null)
     {
         weapon.ToggleShooting(true);
         //Debug.Log ("Should start shooting");
     }
 }
示例#24
0
    void OnTriggerEnter(Collider other)
    {
        IShootable shootable = other.GetComponent <IShootable>();

        if (shootable != null)
        {
            shootable.Interact(this);
        }
    }
示例#25
0
    void IActions.Do()
    {
        int currentMode = MyInputManager.instance.GetFireMode();

        if (currentMode >= 0 && currentMode < ShootsAbility.Count && currentShootAbility != ShootsAbility[currentMode])
        {
            currentShootAbility = ShootsAbility[currentMode];
        }
        currentShootAbility.Shoot();
    }
示例#26
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Destroy(gameObject);
        IShootable shootable = collision.GetComponent <IShootable>();

        if (shootable != null)
        {
            shootable.GetShot();
        }
    }
示例#27
0
    IShootable FindClosestTarget()
    {
        IShootable closestTarget   = null;
        float      closestDistance = 1000.0f;

        foreach (var distanceByTarget in distancesByTargets)
        {
            closestTarget = (distanceByTarget.Value < closestDistance) ? distanceByTarget.Key : closestTarget;
        }
        return(closestTarget);
    }
示例#28
0
 public void Shoot(
     GunComponent gun,
     IShootable ammo,
     EntityCoordinates fromCoordinates,
     EntityCoordinates toCoordinates,
     EntityUid?user = null)
 {
     Shoot(gun, new List <IShootable>(1)
     {
         ammo
     }, fromCoordinates, toCoordinates, user);
 }
示例#29
0
    protected override void Awake()
    {
        base.Awake();

        m_Data    = actor as EnemyScriptableObject; //Cast information
        m_Agent   = GetComponent <NavMeshAgent>();
        shootable = GetComponent <IShootable>();

        //We are taking the value as a "magnitude" but we are comparing it as a sqrMagnitude
        distanceToShoot = Mathf.Pow(m_Data.distanceToShoot, 2f);

        InitializeAgent();
    }
示例#30
0
    public bool AddToList(IShootable weapon)
    {
        if (Enum.IsDefined(typeof(_weaponsID), weapon.ID) && inventory.Count < INVENTORYCAPACITY)
        {
            if (!inventory.Any())
            {
                _heroAnimatior.SetBool("changingWeapon", true);
                _heroAnimatior.SetInteger("weaponID", weapon.ID);
            }
            inventory.Add(weapon);
            if (GetUsingWeapon().ammoInMagazine == 0 && GetUsingWeapon().ammo == 0)
            {
                IShootable weaponTemp = inventory[_usingSlot];
                inventory[_usingSlot]          = inventory[inventory.Count - 1];
                inventory[inventory.Count - 1] = weaponTemp;
                _heroAnimatior.SetBool("changingWeapon", true);
                _heroAnimatior.SetInteger("weaponID", GetUsingWeapon().ID);
            }

            //            Debug.Log(_usingSlot);
            if (inventory.Count == 1)
            {
                SetWeaponActivity(0);
            }

            if (inventory.Count == 2)
            {
                _secondWeaponPosition = 1;
                if (_secondWeaponPosition > inventory.Count - 1)
                {
                    _secondWeaponPosition = 0;
                }
            }

            if (inventory.Count == 3)
            {
                _thirdWeaponPosition = 2;
                if (_thirdWeaponPosition > inventory.Count - 1)
                {
                    _thirdWeaponPosition = 0;
                }
            }

            return(true);
        }
        else
        {
            return(false);
        }
    }