Inheritance: MonoBehaviour
    public IEnumerator Shoot()
    {
        float t = projectile.rate;

        _audio.Play();
        if (_shooted)
        {
            yield return(null);
        }
        if (!_shooted)
        {
            _shooted = true;

            // Start audio
            _audio.Play();
            yield return(new WaitForSeconds(t));


            // The projectile will be instantiated at the coordinates of the fire point (right) or displaced to the left of the player
            if (FindObjectOfType <PlayerCharacter>().flip)
            {
                Vector3          position1 = new Vector3((firePoint.position.x + _n), firePoint.position.y, firePoint.position.z);
                PlayerProjectile proj      = Instantiate(projectile, position1, Quaternion.identity);
            }

            else if (!FindObjectOfType <PlayerCharacter>().flip)
            {
                PlayerProjectile proj = Instantiate(projectile, firePoint.position, Quaternion.identity);
            }

            _shooted = false;
        }
    }
Exemplo n.º 2
0
    void Shoot(float velocity)
    {
        if (ammo > 0)
        {
            animator.SetBool("Shoot", true);
            GameObject prefab = Instantiate(projectile);
            prefab.transform.position = attackPoint.transform.position;

            if (prefab.GetComponent <Rigidbody>())
            {
                Rigidbody rigidbody = prefab.GetComponent <Rigidbody>();
                Vector3   direction = (
                    front.position -
                    attackPoint.transform.position
                    ).normalized;
                rigidbody.velocity = direction * velocity;

                if (prefab.GetComponent <PlayerProjectile>())
                {
                    PlayerProjectile projectile = prefab.GetComponent <PlayerProjectile>();
                    projectile.BonusDamage = velocity;
                }
            }

            ammo--;
            AudioManager.Instance.slingStretch.Play();
            AudioManager.Instance.slingRelease.Play();
            Destroy(prefab, 2.5f);
            ResetSling();
            UpdateUI();
        }
    }
Exemplo n.º 3
0
    void Fire()
    {
        if (isFireable() && GameInput.GetFire(pCode))
        {
            Vector3            shootDirection = aimPoint.transform.position - collisionRange.transform.position;
            GameObject         projectile     = Instantiate(projectilePrefab, aimPoint.transform);
            PlayerProjectile   pp             = projectile.transform.gameObject.GetComponent <PlayerProjectile>();
            ProjectileWhoShoot who            = projectile.transform.GetComponent <ProjectileWhoShoot>();
            who.who = transform.gameObject;

            if (shootDirection.x == 0)
            {
                shootDirection.x += shotDirections[shotSeq];
            }
            else if (shootDirection.y == 0)
            {
                shootDirection.y += shotDirections[shotSeq];
            }

            shotSeq++;
            shotSeq = shotSeq % shotDirections.Length;

            pp.direction = shootDirection.normalized;

            if (normalShotSFX != null && sfx != null)
            {
                // LockOn Sound Effect
                sfx.PlayOneShot(normalShotSFX);
            }

            projectile.transform.SetParent(null);
            fireTimer = 0f;
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        tags = new List <string>();
        foreach (Slot slot in inventory.slots)
        {
            tags.Add(slot.tag);
        }

        if (nextCheckTime < Time.time)
        {
            canShoot      = true;
            nextCheckTime = Time.time + checkDelay;
        }
        if (nextTime < Time.time && canShoot && isStoneSelected() && Input.GetMouseButtonDown(0))
        {
            GetComponent <AudioSource>().PlayOneShot(ThrowRock);
            PlayerProjectile pro = GameObject.Instantiate <PlayerProjectile>(projectile, transform.position, Quaternion.identity, null);
            pro.transform.SetParent(GameObject.FindGameObjectWithTag(Events.RequestSceneName()).transform);

            int i = tags.IndexOf("Rock");

            Events.RemoveItem(i);


            nextTime = Time.time + cooldown;
            canShoot = false;
        }
    }
Exemplo n.º 5
0
    protected override void Shoot() //Ranged Attack
    {
        ChangeHealth(-damage);

        Vector3 pos = gameObject.transform.position;

        pos.y -= 0.1f * transform.localScale.y;
        pos.z  = 1;

        GameObject projectile = Instantiate(projectilePrefab, pos, gameObject.transform.rotation); //Creates a projectile and removes its health from the player

        projectile.transform.localScale = transform.localScale;
        PlayerProjectile projScript = projectile.GetComponent <PlayerProjectile>();

        if (projScript)
        {
            projScript.Damage   = damage;       //Set shot damage
            projScript.Distance = shotDistance; //Set shot damage
            projScript.Origin   = tag;
            if (transform.localScale.x > 0)     //Set shot direction
            {
                projScript.Speed = shotSpeed * Vector2.right;
            }
            else
            {
                projScript.Speed = shotSpeed * Vector2.left;
            }
        }

        //Set thread to turn shooting back on in a short amount of time
        StartCoroutine(DelayNextShot(shotDelay));
    }
    void LaunchProjectile(PlayerProjectile prefab_p)
    {
        PlayerProjectile p = GameObject.Instantiate(prefab_p, weaponBlasterPoint.position, Quaternion.identity);

        p.fpsControllerCore = this;
        p.Launch(fpsCamera.transform.forward, runSpeed + 4);
    }
Exemplo n.º 7
0
    private void Shoot()
    {
        if (!GameController.instance.IsActivate(GameController.ActionType.Shoot))
        {
            return;
        }

        if (shootCooldownTimer > 0)
        {
            shootCooldownTimer -= Time.deltaTime;

            if (shootCooldownTimer <= 0f)
            {
                shootCooldownTimer = 0f;
            }
        }
        else if (Input.GetAxis("Fire1") != 0)
        {
            // Fire
            Transform        projTransform = Instantiate(projectilePrefab, projectilesParent).transform;
            PlayerProjectile proj          = projTransform.GetComponent <PlayerProjectile>();
            proj.direction         = lookDirection;
            projTransform.position = transform.position;

            shootCooldownTimer = shootCooldownDuration;
        }
    }
    public override void Attack()
    {
        GameObject       clone     = Instantiate(projectile, spawnPoint.position, spawnPoint.rotation);
        PlayerProjectile newBullet = clone.GetComponent <PlayerProjectile>();

        newBullet.Fire(transform.forward);
    }
Exemplo n.º 9
0
    private void MakeProjectile(GameObject projectile)
    {
        Vector2          temp  = new Vector2(anime.GetFloat("moveX"), anime.GetFloat("moveY"));
        PlayerProjectile arrow = Instantiate(projectile, transform.position, Quaternion.identity).GetComponent <PlayerProjectile>();

        arrow.Setup(temp, ChooseProjectileDirection());
    }
Exemplo n.º 10
0
    protected override void Shoot()
    {
        PlayerProjectile projectile = ProjectileFactory.CreateProjectile(ProjectileType.PLAYER) as PlayerProjectile;

        projectile.transform.position = shootPosition.position;
        projectile.Launch(shootPosition.forward, ShoudProjectileRecochet(), GameField);
    }
Exemplo n.º 11
0
    private void Shoot()
    {
        GameObjectList   projectiles = GameWorld.Find("PlayerProjectiles") as GameObjectList;
        PlayerProjectile projectile  = new PlayerProjectile(position + new Vector2(0, -60), shootLeft);

        projectiles.Add(projectile);
    }
Exemplo n.º 12
0
 public void FireCross(Vector3 pos, float range)
 {
     for (int i = 1; i < 5; i++)
     {
         var project = new PlayerProjectile();
         project = playerProjectile.MakeInstance(bulletBox.gameObject);
         //project.weaponStats.Init(4);
         project.Init(20);
         project.Setting(damage / 4, range);
         project.transform.position = pos;
         if (i == 1)
         {
             Vector2 targ = new Vector2(pos.x, pos.y + 1.0f);
             project.SetTarget(targ);
         }
         if (i == 2)
         {
             Vector2 targ = new Vector2(pos.x, pos.y + -1.0f);
             project.SetTarget(targ);
         }
         if (i == 3)
         {
             Vector2 targ = new Vector2(pos.x + 1.0f, pos.y);
             project.SetTarget(targ);
         }
         if (i == 4)
         {
             Vector2 targ = new Vector2(pos.x + -1.0f, pos.y);
             project.SetTarget(targ);
         }
     }
 }
Exemplo n.º 13
0
 void OnTriggerStay(Collider collider)
 {
     if (collider.gameObject.tag == "Player" && !onCooldown && !isDead)
     {
         animator.Play("BiteAttack");
         if (colorGhost == GhostType.RED)
         {
             gameManager.Blind(cooldown);
         }
         else
         if (colorGhost == GhostType.BLUE)
         {
             gameManager.TeleportPlayer();
         }
         StartCoroutine(DrainLight(lightDrain));
     }
     else
     if (collider.gameObject.tag == "Projectile")
     {
         PlayerProjectile projectile = collider.gameObject.GetComponent <PlayerProjectile>();
         if (projectile != null)
         {
             DealDamage(projectile.damage);
             Destroy(projectile.gameObject);
         }
     }
 }
Exemplo n.º 14
0
    void SetGemsEffect(GameObject bullet)
    {
        for (int i = 0; i < gemManager.Types.Length; i++)
        {
            switch (gemManager.Types[i])
            {
            case GemManager.GemType.Homing:
                Homing h = bullet.GetComponent <Homing>();
                h.rotSpeed = gemManager.Amounts [i] * HOMING_ROT;
                h.enabled  = true;
                break;

            case GemManager.GemType.Bouncing:
                PlayerProjectile p1 = bullet.GetComponent <PlayerProjectile> ();
                p1.bounces = gemManager.Amounts [i] / 4 + 1;
                p1.enabled = true;
                break;

            case GemManager.GemType.Poison:
                PlayerProjectile p2 = bullet.GetComponent <PlayerProjectile> ();
                p2.poisonDamage = gemManager.Amounts [i] * POISON_DAMAGE;
                p2.enabled      = true;
                break;

            case GemManager.GemType.Vampire:
                PlayerProjectile p3 = bullet.GetComponent <PlayerProjectile> ();
                p3.vampireRecovery = gemManager.Amounts[i];
                p3.enabled         = true;
                break;
            }
        }
    }
Exemplo n.º 15
0
    protected void Shoot()
    {
        GameObject bullet = GameObjectPools.Instance.GetPooledObject(projectileName);

        bullet.transform.position = transform.position;

        PlayerProjectile projectile = bullet.GetComponent <PlayerProjectile>();

        for (short i = 0; i < projectile.particles.Length; i++)
        {
            ParticleSystem.MainModule m = projectile.particles [i].main;
            m.startColor = gemManager.currentColors [i];
            projectile.playParticles [i] = gemManager.currentColors [i] != Color.white;
        }


        Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;

        diff.Normalize();

        float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;

        bullet.transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);

        SetGemsEffect(bullet);
        bullet.SetActive(true);

        SoundManager.PlayClip(2, 0.8f, 1.2f);
    }
Exemplo n.º 16
0
        public override void Initialize(GameObject owner)
        {
            base.Initialize(owner);

            transform = (Transform)GetComponent <Transform>();
            velocity  = (Velocity)GetComponent <Velocity>();
            sprite    = ((SpriteRenderer)GetComponent <SpriteRenderer>()).Sprite;

            PlayerProjectile = GameManager.GetPrefab("RedProjectile");


            projectileSprite = ((SpriteRenderer)PlayerProjectile.GetComponent <SpriteRenderer>()).Sprite;

            health = 7;

            playerOrigin        = new Vector2(360, 580) - sprite.GetCenter();
            flippedPlayerOrigin = VectorMath.RotatePoint(playerOrigin, new Vector2(360, 360), (float)Math.PI) - sprite.GetDimensions();

            transform.Position = playerOrigin;

            isFlipped = false;

            slowSpeed   = 100f;
            normalSpeed = 300f;
        }
    void HitPlayer()
    {
        RaycastHit rayHit;


        float elapseAlive = Time.time - aliveTime;

        if (elapseAlive < 1.2f)
        {
            damageModifier = 1.4f;
        }
        else if (elapseAlive < 5)
        {
            damageModifier = 1;
        }
        else
        {
            damageModifier = 0.2f;
        }


        if (PlayerProjectile.HitRayDirection(transform.position, velocity.normalized, 0.3f, 1 << 9, out rayHit))
        {
            FpsControllerCore.instance.HitParticle(rayHit.point + rayHit.normal * 0.05f, rayHit.normal);
            alive = false;
            FpsControllerCore.instance.TakeDamage(Mathf.FloorToInt(baseDamage * damageModifier));
        }
    }
Exemplo n.º 18
0
    void Fire()
    {
        GameObject       bullet     = Instantiate(bulletPrefab, rb.position + Vector2.up * bulletVerticalOffset, Quaternion.identity);
        PlayerProjectile projectile = bullet.GetComponent <PlayerProjectile>();

        projectile.Fire(lookDirection);
        // call animation for firing
    }
Exemplo n.º 19
0
 public void Init(PlayerBrain pb, TopDownPlayerMotor pm, PlayerProjectile pp, Transform we, UIWidget bb)
 {
     playerBrain      = pb;
     motor            = pm;
     playerProjectile = pp;
     gunEnd           = we;
     bulletBox        = bb;
 }
Exemplo n.º 20
0
    void SetFocused(GameObject ball, bool focused)
    {
        PlayerProjectile projectile = ball.GetComponent <PlayerProjectile>();

        if (projectile != null)
        {
            projectile.focused = focused;
        }
    }
Exemplo n.º 21
0
    public void SecondaryAttack(int shotsLeft)
    {
        if (!secondaryOnCooldown && !primaryOnCooldown || (followUpShot && numShots > 0)) //Fire if primary/secondary attacks are not on cooldown or if followup shot is the one being fired
        {
            Vector3 mousePosition = Input.mousePosition;
            float   radIncrement  = spread / numProjectilesPerShot; //Degrees apart each shot should be from another if firing multiple projectiles

            for (int i = 0; i < numProjectilesPerShot; i++)
            {
                projectileInstance = Instantiate(projectilePrefab, attackHitbox.position, Quaternion.identity) as Rigidbody2D;

                if (projectileInstance.GetComponent <ElementalEffects>() != null) //make sure projectile can have an element
                {
                    projectileInstance.GetComponent <ElementalEffects>().element = projectileInstance.GetComponent <ElementalEffects>().element | projectileElement;
                }

                float angle = GetMouseAngleToPlayer();

                if (numProjectilesPerShot > 1 && numProjectilesPerShot % 2 == 1)                                      //If we shoot more than one projectile, offset their angle and direction fired by the number of shots
                {
                    angle = angle - spread + (radIncrement * (i + 1)) + (radIncrement * (numProjectilesPerShot / 2)); //There is a different formula for even/odd number of projectiles
                }
                else if (numProjectilesPerShot > 1 && numProjectilesPerShot % 2 == 0)
                {
                    angle = angle - spread + (radIncrement * (i + 1)) + ((radIncrement / 2) * (numProjectilesPerShot / 2)); //TODO maybe fix this formula up later, seems way to complex for what it does
                }
                float y = Mathf.Sin(angle);
                float x = Mathf.Cos(angle);
                //print("i: " + i + " Angle: " + Mathf.Rad2Deg*angle + " RadIncrement: " + Mathf.Rad2Deg * radIncrement);
                projectileInstance.AddForce(new Vector3(x, y, 0) * projectileSpeed);
                projectileInstance.transform.Rotate(new Vector3(0, 0, Mathf.Rad2Deg * angle + 90));

                PlayerProjectile projectileScript = projectileInstance.GetComponent <PlayerProjectile>();
                if (isHoming && projectileScript != null) //Pass on homing projectile
                {
                    projectileScript.SetHomingShots(true);
                }

                if (maxBounces > 0) //Pass on bounces
                {
                    projectileScript.SetBounces(maxBounces);
                }

                if (isExplosive) //Pass on explosive
                {
                    projectileScript.ShouldExplode(isExplosive);
                }

                //Set width of projectile to the modifier
                projectileInstance.transform.localScale = new Vector3(projectileInstance.transform.localScale.x * projectileWidthModifier, projectileInstance.transform.localScale.y, projectileInstance.transform.localScale.z);
                //print(projectileInstance.transform.localScale);
            }

            secondaryOnCooldown = true;
            StartCoroutine(SecondaryCooldown(shotsLeft - 1)); //Start routine to put a cooldown on secondary atk
        }
    }
Exemplo n.º 22
0
    private void OnTriggerEnter(Collider collision)
    {
        PlayerProjectile proj = collision.GetComponent <PlayerProjectile>();

        if (proj != null)
        {
            Die();
        }
    }
Exemplo n.º 23
0
    /// <summary>
    /// 스킬에 사용되는 프로젝타일을 등록합니다.
    /// </summary>
    public void SetInit_Projectile(PlayerProjectile projectile)
    {
        if (setSkill.skillMissileSpeed != 0)
        {
            projectile.Add_RigidBody();
        }

        setSkill.projectile = projectile;
    }
Exemplo n.º 24
0
 private void ProcessFiring()
 {
     if (!playerInstance.isProjectileOnCooldown && !playerInstance.isDashing && isTryingToFire)
     {
         PlayerProjectile projectile = Instantiate(projectileToFire, fireSpot.transform.position, fireSpot.transform.rotation);
         projectileCooldownCounter = ProjectileCooldownCounter();
         projectile.direction      = GetProjectileDirection();
         StartCoroutine(projectileCooldownCounter);
     }
 }
Exemplo n.º 25
0
    void SpawnProjectile()
    {
        GameObject       InstProjectile   = Instantiate(projectile, spawn_Projectile_Point.transform.position, Quaternion.identity);
        PlayerProjectile playerProjectile = InstProjectile.GetComponent <PlayerProjectile>();

        if (playerProjectile)
        {
            playerProjectile.direction = transform.parent.forward;
        }
    }
Exemplo n.º 26
0
 public override void triggerEffect(ActionTrigger trigger, PlayerProjectile projectile)
 {
     Debug.Log("ExplosionEffect");
     if (trigger.m_ActionType == "HitTrigger")
     {
         Debug.Log("ExplosionEffect");
         //projectile.m_ProjectileFeatures.m_Damage += m_ExplosionDamage;
         //UiManager.Instance.spawnFloatingText (projectile.transform.position, "+", m_ExplosionDamage);
     }
 }
Exemplo n.º 27
0
 public override void triggerEffect(ActionTrigger trigger, PlayerProjectile projectile)
 {
     Debug.Log("AdditiveDamageEffect");
     if (trigger.m_ActionType == "Bounce")
     {
         Debug.Log("AdditiveDamageEffect");
         projectile.m_ProjectileFeatures.m_Damage += m_BonusDamage;
         UiManager.Instance.spawnFloatingText(projectile.transform.position, "+", m_BonusDamage);
     }
 }
Exemplo n.º 28
0
    private void Shoot()
    {
        Vector2          playerPosition = new Vector2(transform.position.x, transform.position.y);
        Vector2          projDirection  = mousePos - playerPosition;
        Vector2          projTarget     = playerPosition + (projDirection.normalized * firingDistance);
        GameObject       proj           = Instantiate(projectile, transform.position, firePoint.transform.rotation);
        PlayerProjectile projScript     = proj.GetComponent <PlayerProjectile>();

        projScript.init(projTarget, projDirection, playerDamage, knockback);
    }
Exemplo n.º 29
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        PlayerProjectile projectile = collision.gameObject.GetComponent <PlayerProjectile>();

        if (projectile != null)
        {
            projectile.Hit();
            Hit(projectile.GetDamage());
        }
    }
Exemplo n.º 30
0
    public static void HitPlayer(Vector3 position, Vector3 direction, float damage = 2, float length = 1)
    {
        RaycastHit rayHit;

        if (PlayerProjectile.HitRayDirection(position, direction, length, 1 << 9, out rayHit))
        {
            FpsControllerCore.instance.HitParticle(rayHit.point + rayHit.normal * 0.05f, rayHit.normal);
            Debug.Log("hit player");
            FpsControllerCore.instance.TakeDamage((int)damage);
        }
    }