Inheritance: MonoBehaviour
Exemplo n.º 1
0
    //we want to use the player as a reference for animating and giving a simple AI.
    void Start()
    {
        Player           = GameObject.Find("Player");
        ControllerScript = Player.GetComponent <PlayerController> ();
        PHealthScript    = Player.GetComponent <playerHealth> ();

        controller = GetComponent <CharacterController> ();
        rend       = GetComponent <SpriteRenderer> ();
        target     = GameObject.FindGameObjectWithTag("Player");
        //Physics.IgnoreCollision (target.GetComponent<Collider> (), GetComponent<Collider> ());
        Physics.IgnoreCollision(target.transform.root.GetComponent <Collider> (), GetComponent <Collider> ());
        //Physics.IgnoreCollision (SlashWave.GetComponent<BoxCollider> (), GetComponent<Collider> ());

        origX = transform.localScale.x;
        //here it makes it ignore other enemy colliders so they can't get caught on each other.
        GameObject[] enemies = GameObject.FindGameObjectsWithTag("enemy");

        foreach (GameObject en in enemies)
        {
            if (en.GetComponent <Collider> () != GetComponent <Collider> ())
            {
                Physics.IgnoreCollision(GetComponent <Collider> (), en.GetComponent <Collider> ());
            }
        }
        bullet = Instantiate(enemyBullet, bulletPosition.position, Quaternion.Euler(0, 0, 0)) as GameObject;
        bullet.GetComponent <SpriteRenderer> ().enabled = false;
        bulletrb     = bullet.GetComponent <Rigidbody> ();
        bulletScript = bullet.GetComponent <enemyBullet> ();

        HealthScript = GetComponent <enemyHealth> ();
    }
Exemplo n.º 2
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     //if our missle collider collides with a collider of an enemy
     if (collision.gameObject.layer == LayerMask.NameToLayer("Shootable"))
     {
         //stop the missle
         myPC.removeForce();
         //instatiate the explosion
         Instantiate(explosionObject, transform.position, transform.rotation);
         Destroy(gameObject);
     }
     //check if the game object hit is an enemy
     if (collision.tag == "Enemy")
     {
         //reference to the enemyHealth
         enemyHealth hurtEnemy = collision.gameObject.GetComponent <enemyHealth>();
         if (hurtEnemy != null)
         {
             hurtEnemy.enemyHit(missleDamage);
         }
         else
         {
             Debug.Log("Null object reference");
         }
     }
 }
Exemplo n.º 3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float melee = Input.GetAxis("Fire2");

        if (melee > 0 && nextMelee < Time.time && !(myPC.getRunning()))
        {
            myAnim.SetTrigger("gunMelee");
            nextMelee = Time.time + meleeRate;

            //do damage
            Collider[] attacked = Physics.OverlapSphere(transform.position, knockBackRadius, shootableMask);

            int i = 0;
            while (i < attacked.Length)
            {
                if (attacked[i].tag == "Enemy")
                {
                    enemyHealth doDamage = attacked[i].GetComponent <enemyHealth>();
                    doDamage.addDamage(damage);
                    doDamage.damageFX(transform.position, transform.localEulerAngles);
                }
                i++;
            }
        }
    }
Exemplo n.º 4
0
 private void Start()
 {
     anim         = GetComponent <Animator>();
     _enemyHealth = GetComponent <enemyHealth>();
     rb           = GetComponent <Rigidbody2D>();
     player       = GameObject.Find("Player");
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        float melee = Input.GetAxis("Fire2"); //Left Alt ou botão esquerdo mouse

        if (melee > 0 && nextMelee < Time.time && !(myPC.GetRunning()))
        {
            myAnim.SetTrigger("gunMelee");     //Já é automaticamente true por um momento gatilho
            nextMelee = Time.time + meleeRate; //Tempo em segundos desde o inicio até "agora" + rate

            //do Damage
            //Cria array de colider que salva tudo que tiver dentro dessa overlap sphere
            //Parametros --- Lugar onde ela é criada, tamanho dela e masks que ela afetara
            Collider[] attacked = Physics.OverlapSphere(transform.position, knockBackRadius, shootableMask);

            for (int i = 0; i < attacked.Length; i++)
            {
                if (attacked[i].GetComponent <Collider>().tag == "Enemy")
                {
                    enemyHealth theEnemyHealth = attacked[i].GetComponent <enemyHealth>(); //tenta achar o script de vida

                    if (theEnemyHealth != null)
                    {
                        theEnemyHealth.addDamage(damage);
                        theEnemyHealth.damageFX(transform.position, -transform.forward);
                    }
                }
            }
        }
    }
Exemplo n.º 6
0
    void Shoot()
    {
        timer = 0f;

        //gunAudio.Play();

        gunLight.enabled = true;

        //gunParticles.Stop();
        //gunParticles.Play();

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

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

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            enemyHealth eHealth = shootHit.collider.GetComponent <enemyHealth>();
            if (eHealth != null)
            {
                eHealth.TakeDamage(damagePerShot, shootHit.point);
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
 void Start()
 {
     _health    = GetComponent <enemyHealth>();
     _manager   = managerObject.GetComponent <gManager>();
     _waypoints = GameObject.FindGameObjectWithTag("Waypoints").transform;
     NextWaypoint();
 }
Exemplo n.º 8
0
 void Awake()
 {
     m_shootCooldown = 0f;
     m_sight         = GetComponent <enemySight> ();
     m_health        = GetComponent <enemyHealth> ();
     m_player        = FindObjectOfType <playerController> ().gameObject;
 }
Exemplo n.º 9
0
 void Awake()
 {
     player  = GameObject.FindGameObjectWithTag("Player");
     pHealth = player.GetComponent <playerHealth>();
     eHealth = GetComponent <enemyHealth>();
     anim    = GetComponent <Animator>();
 }
Exemplo n.º 10
0
 void OnCollisionEnter2D(Collision2D enemy)
 {
     if (enemy != null)
     {
         Instantiate(explosionRef, this.transform.position, Quaternion.identity);
         if (enemy.gameObject.tag == "enemy")
         {
             Destroy(this.gameObject);
             enemyHealth damage = enemy.gameObject.GetComponent <enemyHealth>();
             damage.flash();
             damage.health.Damage(bullet_damage);
         }
         else if (enemy.gameObject.tag == "Player")
         {
             Destroy(this.gameObject);
             enemy.gameObject.GetComponent <TankMovement>().moveSpeed = 10f;
             web_free(this, EventArgs.Empty);
         }
         else if (enemy.gameObject.tag != "EnemyBullet" &&
                  enemy.gameObject.tag != "PlayerBullet")
         {
             Destroy(this.gameObject);
         }
     }
 }
Exemplo n.º 11
0
    //public int playerMoney = 0;
    //Text playerMoneyText;

    #endregion

    // Use this for initialization
    void Awake()
    {
        //playerMoneyText = GameObject.Find("moneyAmount").GetComponent<Text>();
        //playerMoneyText.text = playerMoney.ToString();
        money         = GameObject.Find("moneyPanel").GetComponent <moneyIncreaser>();
        shootableMask = LayerMask.GetMask("Shootable");                    //Shootable layers, in layers. Find the shootable layer.
        gunLine       = GetComponent <LineRenderer>();                     //line renderer reference

        shootRay.origin    = transform.position;                           //Ray is being shot from where instantiated
        shootRay.direction = transform.forward;                            //Shoot forward from position
        gunLine.SetPosition(0, transform.position);                        //where to start and finish drawing

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) //chose the ray, out value will bring information as to what we hit, range is how far it will shoot, layermask to determine what can be hit/shot (shootable)
        {
            if (shootHit.collider.tag == "zombie")                         //if we have shot an enemy
            {
                //playerMoney++;
                money.increaseMoney();
                SetMoneyText();
                enemyHealth theEnemyHealth = shootHit.collider.GetComponent <enemyHealth>(); //get enemy health
                if (theEnemyHealth != null)                                                  //if we find it, and its not null
                {
                    theEnemyHealth.addDamage(damage);                                        //make damage
                    theEnemyHealth.damageFX(shootHit.point, -shootRay.direction);
                }
            }
            //Hit an enemy will be entered here
            gunLine.SetPosition(1, shootHit.point); //endpoint of gunline, what did i hit, where did i hit it
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); //if nothing is hit, shoot a ray within the range we set
        }
    }
Exemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        Vector3 explosionPos = transform.position;

        Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
        foreach (Collider hit in colliders)
        {
            Rigidbody rb = hit.GetComponent <Rigidbody>();

            if (rb != null)
            {
                rb.AddExplosionForce(power, explosionPos, radius, 3.0f, ForceMode.Impulse);
            }
            if (hit.tag == "Player")
            {
                playerHealth thePlayerHealth = hit.gameObject.GetComponent <playerHealth>();
                thePlayerHealth.addDamage(damage);
            }
            else if (hit.tag == "Enemy")
            {
                enemyHealth theEnemyHealth = hit.gameObject.GetComponent <enemyHealth>();
                theEnemyHealth.addDamage(damage);
            }
        }
    }
 // Use this for initialization
 void Awake()
 {
     eHealth = GameObject.FindGameObjectWithTag ("enemy").GetComponent<enemyHealth> ();
     pStats = GameObject.FindGameObjectWithTag ("Player").GetComponent<playerStats> ();
     chckpoint = GameObject.Find("CheckPoints");
     tut = chckpoint.GetComponent<TutorialScript>();
 }
Exemplo n.º 14
0
    //detects the are in front of player for enemies and other objects
    public void HitDetection()
    {
        player.CanControl = true;
        Collider[] cols = new Collider[1];

        Physics.OverlapBoxNonAlloc(transform.TransformPoint(hitBoxLocation), hitboxSize / 2, cols, transform.rotation, hitDetectionLayers);

        if (cols[0] != null)
        {
            enemyHealth e = cols[0].GetComponent <enemyHealth>();
            //if we find an enemy collider, do damage and STUN
            if (e != null)
            {
                //if there's obstacle between enemy and player, continue to next iteration
                if (Physics.Linecast(health.centerPoint, e.centerPoint, blockingLayers))
                {
                    return;
                }

                //stun in enemy script
                e.takeDamage(damage, gameObject);
                SoundEngine.instance.PlaySound("swordImpact", e.transform.position, null);
            }
        }
    }
Exemplo n.º 15
0
	// Use this for initialization
	void Awake () {
        shoottableMask = LayerMask.GetMask("Shootable");
        gunLine = GetComponent<LineRenderer>();

        shootRay.origin = transform.position;
        shootRay.direction = transform.forward;
        gunLine.SetPosition(0, transform.position);

        if (Physics.Raycast(shootRay, out shootHit, range, shoottableMask))
        {
            if(shootHit.collider.tag == "Enemy")
            {
                enemyHealth theEnemyHealth = shootHit.collider.GetComponent<enemyHealth>();
                if(theEnemyHealth != null)
                {
                    theEnemyHealth.addDamage(damage);
                    theEnemyHealth.damageFX(shootHit.point, -shootRay.direction);
                }
            }
            //Hit an enemy goes here
            gunLine.SetPosition(1, shootHit.point);
        }

        else gunLine.SetPosition(1, shootRay.origin + shootRay.direction*range);
	}
Exemplo n.º 16
0
    NavMeshAgent nav;     //抓取enemy的nav组件

    void Awake()
    {
        player  = GameObject.FindGameObjectWithTag("Player").transform; //绑定玩家
        pHealth = player.GetComponent <playerHealth> ();                //绑定玩家生命值
        eHealth = GetComponent <enemyHealth> ();                        //绑定当前enemy生命值
        nav     = GetComponent <NavMeshAgent>();                        //绑定nav组件
    }
Exemplo n.º 17
0
    void Update()
    {
        // calulate distance between bullet and target and move towards it
        float timeInterval = Time.time - startTime;

        gameObject.transform.position = Vector3.Lerp(startPosition, targetPosition, timeInterval * speed / distance);



        // confirm enemy still exists
        if (gameObject.transform.position.Equals(targetPosition))
        {
            if (target != null)
            {
                // retrieve target's healthbar and change it
                Transform   healthBarTransform = target.transform.Find("HealthBar");
                enemyHealth healthBar          = healthBarTransform.gameObject.GetComponent <enemyHealth>();
                healthBar.currentHealth -= Mathf.Max(damage, 0);


                // when enemy health reaches zero, destroy it
                if (healthBar.currentHealth <= 0)
                {
                    AudioSource audioSource = target.GetComponent <AudioSource>();
                    AudioSource.PlayClipAtPoint(audioSource.clip, transform.position);
                    Destroy(target);
                    GameManager.Gold += 10;
                }
            }
            Destroy(gameObject);
        }
    }
Exemplo n.º 18
0
    // Use this for initialization
    void Start()
    {
        Player           = GameObject.Find("Player");
        ControllerScript = Player.GetComponent <PlayerController> ();
        PHealthScript    = Player.GetComponent <playerHealth> ();

        controller = GetComponent <CharacterController> ();
        controller.detectCollisions = false;

        target = GameObject.FindGameObjectWithTag("Player");
        //Physics.IgnoreCollision (target.GetComponent<Collider> (), GetComponent<Collider> ());
        Physics.IgnoreCollision(target.transform.root.GetComponent <Collider> (), GetComponent <Collider> ());


        Devilchu = GameObject.FindGameObjectWithTag("Devilchu");
        Physics.IgnoreCollision(Devilchu.transform.root.GetComponent <Collider> (), GetComponent <Collider> ());

        MyAnimation = gameObject.transform.FindChild("Animation").GetComponent <Animator> ();

        SlashWave = gameObject.transform.FindChild("Animation/LeafBody/LeafLLeg/SlashWave").gameObject;
        SlashWave.GetComponent <BoxCollider> ().enabled    = false;
        SlashWave.GetComponent <SpriteRenderer> ().enabled = false;

        HealthScript = gameObject.GetComponent <enemyHealth> ();
    }
    public AudioClip explosionAudio; //Som da explosao

    // Start is called before the first frame update
    void Awake()
    {
        Vector3 explosionPos = transform.position;                          //Pega a posição do objeto pra criar a Overlap Sphere

        Collider[] colliders = Physics.OverlapSphere(explosionPos, radius); //Cria a overlap sphere naquele ponto com aquele raio
        foreach (Collider hit in colliders)
        {
            Rigidbody rb = hit.GetComponent <Rigidbody>(); //Pega o rigidbody do que foi acertado
            //Se rb foi encontrado no objeto
            if (rb != null)
            {
                Debug.Log("Acertou");
                //Built-in function --- Forca da explosao, ponto da onde explodiu, raio
                //Modificador que joga pra cima, modo de forca = impulso
                rb.AddExplosionForce(power, explosionPos, radius, 3.0f, ForceMode.Impulse);
                if (hit.tag == "Player")
                {
                    playerHealth thePlayerHealth = hit.gameObject.GetComponent <playerHealth>(); //Pq aqui é so o Collider
                    thePlayerHealth.addDamage(damage);
                }
                else if (hit.tag == "Enemy")
                {
                    enemyHealth theEnemyHealth = hit.gameObject.GetComponent <enemyHealth>();
                    theEnemyHealth.addDamage(damage);
                    theEnemyHealth.addFire();
                }
            }
        }
        AudioSource.PlayClipAtPoint(explosionAudio, transform.position, 1f);
    }
Exemplo n.º 20
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Enemy")
     {
         enemyHealth hurtEnemy = other.gameObject.GetComponent <enemyHealth>();
         hurtEnemy.AddDamage(weaponDamage);
     }
 }
Exemplo n.º 21
0
 void Start()
 {
     OriginalPosition    = transform.position;
     rb2d                = GetComponent <Rigidbody2D> ();
     currentPlayerHealth = maxPlayerHealth;
     attackScript        = this.gameObject.GetComponent <PlayerAttack> ();
     enemyScript         = this.gameObject.GetComponent <enemyHealth> ();
 }
Exemplo n.º 22
0
 void OnTriggerEnter(Collider collision)
 {
     if (collision.gameObject.tag == "Enemy")
     {
         enemy = collision.gameObject.GetComponent <enemyHealth>();
         enemy.Damage(damage);
     }
 }
Exemplo n.º 23
0
    UnityEngine.AI.NavMeshAgent nav; //抓取enemy的nav组件

    void Awake()
    {
        key     = GameObject.FindGameObjectWithTag("key").transform;
        player  = GameObject.FindGameObjectWithTag("Player").transform;
        pHealth = player.GetComponent <playerHealth>();
        eHealth = GetComponent <enemyHealth>();                 //绑定当前enemy生命值
        nav     = GetComponent <UnityEngine.AI.NavMeshAgent>(); //绑定nav组件
    }
Exemplo n.º 24
0
 void Awake()
 {
     // Set up the references.
     player   = GameObject.FindGameObjectWithTag("Player").transform;
     nav      = GetComponent <UnityEngine.AI.NavMeshAgent>();
     playerHp = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth>();
     enemyHp  = GameObject.FindGameObjectWithTag("Enemy").GetComponent <enemyHealth>();
 }
Exemplo n.º 25
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.layer == (7) && isHitting)
     {
         enemyhealth         = collision.gameObject.GetComponent <enemyHealth>();
         enemyhealth.health -= damage;
     }
 }
Exemplo n.º 26
0
 private void Start()
 {
     //player = GameObject.FindGameObjectWithTag("Player").GetComponent<playerController>();
     //enemy = GameObject.FindGameObjectWithTag("Enemy").GetComponent<enemy>();
     rb          = GetComponent <Rigidbody2D>();
     enemy       = GetComponent <enemyHealth>();
     rb.velocity = moveDir * speed;
     puller      = objectPuller.Instance;
 }
Exemplo n.º 27
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Enemy")
        {
            enemyHealth hurtEnemy = other.gameObject.GetComponent <enemyHealth>();
            hurtEnemy.AddDamage(weaponDamage);

            playerAS.PlayOneShot(hitSound);
        }
    }
Exemplo n.º 28
0
    void Start()
    {
        //sets the timeSinceBullet equal to current time
        timeSinceBullet = Time.time;

        //used to get the enemy health
        GameObject enemyAI = GameObject.Find("enemy_AI");

        enemyHealth = enemyAI.GetComponent <enemyHealth>();
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        enemyHealth enemy = collision.GetComponent <enemyHealth>();

        if (enemy != null)
        {
            enemy.takeDamage(damage);
        }
        Destroy(gameObject);
    }
Exemplo n.º 30
0
    private void Start()
    {
        player       = GameObject.Find("Player");
        animator     = GetComponent <Animator>();
        myNavAgent   = GetComponent <UnityEngine.AI.NavMeshAgent>();
        health       = GetComponent <enemyHealth>();
        prevLocation = transform.position;

        StartCoroutine(AIDelay());
    }
Exemplo n.º 31
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Enemy")
     {
         enemyHealth theEnemyHealth = other.GetComponent <enemyHealth>();
         if (theEnemyHealth != null)
         {
             theEnemyHealth.addDamage(damage);
         }
     }
 }
 // Use this for initialization
 void Awake()
 {
     Instance = this;
     attackTime = Time.time;
     npc = GetComponent<NavMeshAgent>();
     stats = player.GetComponent<playerStats>();
     layerMask = ~layerMask;
     enemy = this.GetComponent<enemyHealth>();
     test = player.GetComponent<PlayerMove>();
     isNear = false;
     isDetected = false;
 }
Exemplo n.º 33
0
 // Use this for initialization
 void Awake()
 {
     isDead = false;
     Instance = this;
     tut = chckPoints.GetComponent<TutorialScript>();
 }