Пример #1
0
    void fire()
    {
        //if your current ammo is empty, we try to reload
        if (useClip.currentClip == 0)
        {
            useClip.reload();
        }
        else         //you can fire if u have ammo in your clip
        {
            /*Handles player shooting bullets that checks within a line (hitscan)*/
            firingOrigin  = new Vector2(firingPoint.position.x, firingPoint.position.y);
            mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
                                        Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
            hit = Physics2D.Raycast(firingOrigin, mousePosition - firingOrigin, shootingDistance);

            //Make sure that the firingOrigin is far from the player gameObject
            //to ensure that the raycast hits the enemies and not collide with the player itself
            //and tag all enemies with the same tag to compare
            if (hit && hit.collider.CompareTag("Enemy"))
            {
                damaging = hit.collider.GetComponent <enemyBehavior>();
                damaging.currentHealth--;
            }

            //fires one bullet, subtracting from the current ammo
            useClip.currentClip--;
        }
    }
Пример #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        enemyLayer = LayerMask.LayerToName(collision.gameObject.layer);
        if (enemyLayer == "Enemy")
        {
            enemyBehavior   enemy    = collision.GetComponent <enemyBehavior>();
            obstacleHandler obstacle = collision.GetComponent <obstacleHandler>();
            if (enemy != null)
            {
                if (!zero.GetComponent <Animator>().GetBool("isGrounded"))
                {
                    enemy.takeDamage(dmg1);
                }
                else
                {
                    switch (zero.GetComponent <Animator>().GetInteger("noOfClicks"))
                    {
                    case 1:
                        enemy.takeDamage(dmg1);
                        break;

                    case 2:
                        enemy.takeDamage(dmg2);
                        break;

                    case 3:
                        enemy.takeDamage(dmg3);
                        break;
                    }
                }
            }

            if (obstacle != null)
            {
                if (!zero.GetComponent <Animator>().GetBool("isGrounded"))
                {
                    enemy.takeDamage(dmg1);
                }
                else
                {
                    switch (zero.GetComponent <Animator>().GetInteger("noOfClicks"))
                    {
                    case 1:
                        obstacle.takeDamage(dmg1);
                        break;

                    case 2:
                        obstacle.takeDamage(dmg2);
                        break;

                    case 3:
                        obstacle.takeDamage(dmg3);
                        break;
                    }
                }
            }
        }
    }
Пример #3
0
 void Awake()
 {
     key 		= npc.GetComponent <securityBehavior> ();
     //badge 		= maria.GetComponent <mariaBehavior> ();
     badge 		= picture.GetComponent <pictureScript> ();
     taken 		= gui.GetComponent <guiSystem> ();
     message 	= text.GetComponent <uiSystem> ();
     Enemy 		= enemy.GetComponent <enemyBehavior> ();
 }
Пример #4
0
 public virtual void Dead()
 {
     currentBehavior = enemyBehavior.Dead;
     if (anim != null)
     {
         anim.SetDead();
     }
     this.enabled = false;
 }
Пример #5
0
    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.tag == "ball" || collider.gameObject.tag == "multiball")
        {
            //when the ball hits the powerup, the powerup activates

            if (rand == 0) //DEX MODIFIER POWER UP

            //find all the enemies so they know to increase their dex modifier
            {
                enemies = GameObject.FindGameObjectsWithTag("enemy");

                foreach (GameObject enemy in enemies)
                {
                    dexPower = enemy.GetComponent <enemyBehavior>();


                    dexPower.dexPowerup();
                }
            }

            if (rand == 1) //LARGER BALL

            //find all the balls, no matter what they're tagged
            {
                string[] allballs = { "ball", "multiball" };

                foreach (string tag in allballs)
                {
                    GameObject[] balls = GameObject.FindGameObjectsWithTag(tag);

                    foreach (GameObject anyball in balls)
                    {
                        bigball = anyball.GetComponent <ballcontrol>();

                        bigball.largerBall();
                    }
                }
            }

            if (rand == 2) //MULTIBALL
            {
                multiball.Multiball();
            }



            Destroy(gameObject, 0f); //destroy the powerup immediately so the ball doesn't bounce off of it
        }

        if (collider.gameObject.tag == "Respawn")
        {
            Destroy(gameObject, 0f);
        }
    }
Пример #6
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        enemyBehavior enemy = collision.GetComponent <enemyBehavior>();

        if (enemy != null)
        {
            enemy.Die();
        }

        Destroy(gameObject);
    }
Пример #7
0
    void OnCollisionEnter(Collision collision)
    {
        enemyBehavior evade = collision.collider.GetComponent <enemyBehavior>();

        if (collision.gameObject.name == "coin")
        {
            Destroy(collision.gameObject);
            enemyBehavior script = GetComponent <enemyBehavior>();
            script.evade = script.evade == true;
        }
    }
Пример #8
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag != "Level")
     {
         enemyBehavior eb = other.gameObject.GetComponentInParent <enemyBehavior>();
         if (eb != null)
         {
             eb.TakeDamage(other.gameObject);
         }
         DestroyProjectile();
     }
 }
Пример #9
0
    // Use this for initialization
    void Start()
    {
        enemy = GameObject.FindWithTag("enemy").GetComponent <enemyBehavior> ();
        speed = 3;
        animationController = this.GetComponent <Animator> ();
        rb              = this.GetComponent <Rigidbody2D> ();
        rb.bodyType     = RigidbodyType2D.Dynamic;
        rb.gravityScale = 0;         // want collision but it's topdown so there's no gravity
        particles       = this.GetComponent <ParticleSystem>();

        // handling choosing a random start position for player
        int randPos = Random.Range(0, 4);        // choosing random index in startPositions array

        rb.transform.position = startPositions[randPos];
    }
Пример #10
0
 // Use this for initialization
 void Start()
 {
     EnemiesPresent             = false;
     health                     = playerChar.GetComponent <PlayerHealth>();
     enemyDamage                = enemyDamageType.GetComponent <EnemyAttackSegC>();
     enemyHealth                = enemyType.GetComponent <enemyBehavior>();
     playerHP                   = health.maxHp;
     enemyHealth.startingHealth = enemyHealthOrigin;
     enemyDamage.damage         = enemyDamageOrigin;
     NumEnemies                 = new GameObject[numberOfEnemies];
     FirstSpawn                 = SpawnOne.GetComponent <Waves>();
     SecondSpawn                = SpawnTwo.GetComponent <Waves>();
     ThirdSpawn                 = SpawnThree.GetComponent <Waves>();
     spawn1                     = SpawnEnemies();
     spawn2                     = SpawnEnemiesTwo();
 }
Пример #11
0
    void straightShotMode(float distance)
    {
        // Debug.DrawRay(firingOrigin, fireDirection);

        hit = Physics2D.Raycast(firingOrigin, fireDirection);
        updateRendererPosititions(lineRenderers[1], hit, fireDirection, distance);

        if (hit && hit.collider.CompareTag("Enemy"))
        {
            damaging = hit.collider.GetComponent <enemyBehavior>();
            // Debug.Log(Time.deltaTime);

            damaging.currentHealth -= (Time.deltaTime) * dps;
            //damaging.currentHealth -= 1;
        }
    }
Пример #12
0
    void spreadShotMode()
    {
        for (int i = 0; i < spreadHits.Length; i++)
        {
            spreadHits[i] = Physics2D.Raycast(firingOrigin, spreadDirections[i], shootingDistance);
            hit           = spreadHits[i];
            // Debug.DrawRay(firingOrigin, spreadDirections[i]);
            updateRendererPosititions(lineRenderers[i], spreadHits[i], spreadDirections[i], shootingDistance);
            if (hit && hit.collider.CompareTag("Enemy"))
            {
                damaging = hit.collider.GetComponent <enemyBehavior>();
                // Debug.Log(Time.deltaTime);
                Debug.Log("weapon: " + i + " hit");

                damaging.currentHealth -= (Time.deltaTime) * dps;
            }
        }
    }
Пример #13
0
    // Update is called once per frame
    void Update()
    {
        //transform.Translate(Vector3.forward * 6.8f * speed * Time.deltaTime);

        Ray        ray = new Ray(this.transform.position, this.transform.forward);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo, 1))

        {
            hitPoint = hitInfo.point;
            GameObject go  = hitInfo.collider.gameObject;
            Vector3    dir = go.transform.position;

            Debug.Log(go);
            enemyBehavior eb = go.gameObject.GetComponentInParent <enemyBehavior>();
            if (eb != false)
            {
                eb.TakeDamage(go);
            }

            DestroyProjectile();
        }
    }
Пример #14
0
 protected void ChangeBehavior(enemyBehavior newBehavior)
 {
     // TODO: implement on central method for changes.
 }