// Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag("Player"); dc = GetComponent <damageController>(); rb = GetComponent <Rigidbody2D>(); sr = GetComponent <SpriteRenderer>(); audio = GetComponent <AudioSource>(); dc.immune = true; mSpeed = 0.3f; move = new Sprite[4]; move[0] = Resources.Load <Sprite>("slug/Move/1"); move[1] = Resources.Load <Sprite>("slug/Move/2"); move[2] = Resources.Load <Sprite>("slug/Move/3"); move[3] = Resources.Load <Sprite>("slug/Move/4"); heal = new Sprite[4]; heal[0] = Resources.Load <Sprite>("slug/Heal/1"); heal[1] = Resources.Load <Sprite>("slug/Heal/2"); heal[2] = Resources.Load <Sprite>("slug/Heal/3"); heal[3] = Resources.Load <Sprite>("slug/Heal/4"); trans = new Sprite[4]; trans[0] = Resources.Load <Sprite>("slug/Trans/1"); trans[1] = Resources.Load <Sprite>("slug/Trans/2"); trans[2] = Resources.Load <Sprite>("slug/Trans/3"); trans[3] = Resources.Load <Sprite>("slug/Trans/4"); StartCoroutine(Walk()); }
// Collision detection void OnTriggerEnter2D(Collider2D collision) { damageController dc = collision.gameObject.GetComponent <damageController>(); //local collision counter for enemy; natCol is initialized at 1 if (collision.tag == "Enemy") { natCol++; } // If it hits the player if (collision.tag == "Player") { // Does damage dc.doDamage(3, "none", originalPos, 0f); // Self Destructs Destroy(this.gameObject); } else if (collision.tag == "Wall" || collision.tag == "PowerBlock") { //spawn particles Destroy(this.gameObject); } //there's going to be a collision when the projectile is initialized; given this, each projectile //will have an odd-numbered number of collisions; damage will register at that point if (collision.gameObject.tag == "Enemy" && natCol % 2 != 0) { dc.doDamage(3, "none", originalPos, 0f); Destroy(this.gameObject); // collision.gameObject.GetComponent<turretController>().genTurret = true; } }
// Use this for initialization void Start() { // Finds the player and its script player = GameObject.FindGameObjectWithTag("Player"); dc = player.GetComponent <damageController>(); // Initializes the health bar HealthBar = GetComponent <Image>(); HealthBar.fillAmount = dc.getHealth(); }
// Collision detection private void OnCollisionEnter2D(Collision2D collision) { // If it collided with the player if (collision.gameObject == player) { // Does damage damageController dc = collision.gameObject.GetComponent <damageController>(); dc.doDamage(3, "none", transform.position, 1.5f); } }
// Use this for initialization void Start() { pc = GetComponent <playerController>(); dc = GetComponent <damageController>(); ChromaticAberrationModel.Settings CAS = normal.chromaticAberration.settings; CAS.intensity = 0; normal.chromaticAberration.settings = CAS; UserLutModel.Settings ULS = normal.userLut.settings; ULS.contribution = 0; normal.userLut.settings = ULS; }
private void OnTriggerStay2D(Collider2D collision) { // If it's triggered by the player or an enemy if (collision.CompareTag("Player") || collision.CompareTag("Enemy")) { // Deals falling damage if the target can't fly. damageController dc = collision.gameObject.GetComponent <damageController>(); if (!dc.getFlying()) { dc.doDamage(0, "fall", transform.position, -1.5f); } } }
// Called on colission void OnTriggerEnter2D(Collider2D collision) { // If it collided with the player give the player helth and destroys itself if (collision.CompareTag("Player")) { // Get the player script damageController dc = collision.gameObject.GetComponent <damageController>(); // If the player isn't at max health if (dc.getHealth() != dc.getMaxHealth()) { // Gives the player health and then self destructs dc.giveHealth(amount); GameObject H1 = Instantiate(heal1, transform.position, Quaternion.identity); GameObject H2 = Instantiate(heal2, transform.position, Quaternion.identity); Destroy(this.gameObject); } } }
// Use this for initialization void Start() { mSpeed = 2f; isSlowed = false; dc = GetComponent <damageController>(); rb = GetComponent <Rigidbody2D>(); /* * bc = GetComponent<BoxCollider2D>(); * cc = GetComponent<CircleCollider2D>(); * cc.enabled = false; */ ammo = maxAmmo; stamina = maxStamina; gameObject.GetComponent <TrailRenderer>().enabled = false; alpf = mainCamera.GetComponent <AudioLowPassFilter>(); alpf.enabled = false; }
// Collision detection void OnTriggerEnter2D(Collider2D collision) { // If it hits an enemy if (collision.tag == "Enemy") { // Does damage damageController dc = collision.gameObject.GetComponent <damageController>(); int damage = 2; float knockback = 0.5f; dc.doDamage(damage, "none", originalPos, knockback); // Self Destructs Destroy(this.gameObject); } else if (collision.tag == "Wall" || collision.tag == "PowerBlock") { //spawn particle effect Destroy(this.gameObject); } }
// Collision detection void OnTriggerEnter2D(Collider2D collision) { // If it collides with the enemy if (collision.CompareTag("Enemy") && canSwing == false) { // Does full damage if (fullPower) { damageController dc = collision.gameObject.GetComponent <damageController>(); dc.doDamage(4, "none", player.transform.position, 0.5f); } // Does decreased damage else { damageController dc = collision.gameObject.GetComponent <damageController>(); dc.doDamage(1, "none", player.transform.position, 0f); } } }
// Use this for initialization void Start() { canMove = true; mSpeed = .7f; player = GameObject.FindGameObjectWithTag("Player"); startLocation = transform.position; searchLocation = startLocation; rb = gameObject.GetComponent <Rigidbody2D>(); dc = GetComponent <damageController>(); sr = GetComponent <SpriteRenderer>(); stepSound = GetComponent <AudioSource>(); still = sr.sprite; i = -1; right = new Sprite[10]; right[0] = Resources.Load <Sprite>("EnemyAnim/RN1"); right[1] = Resources.Load <Sprite>("EnemyAnim/RN2"); right[2] = Resources.Load <Sprite>("EnemyAnim/RN3"); right[3] = Resources.Load <Sprite>("EnemyAnim/RN4"); right[4] = Resources.Load <Sprite>("EnemyAnim/RN5"); right[5] = Resources.Load <Sprite>("EnemyAnim/RY1"); right[6] = Resources.Load <Sprite>("EnemyAnim/RY2"); right[7] = Resources.Load <Sprite>("EnemyAnim/RY3"); right[8] = Resources.Load <Sprite>("EnemyAnim/RY4"); right[9] = Resources.Load <Sprite>("EnemyAnim/RY5"); left = new Sprite[10]; left[0] = Resources.Load <Sprite>("EnemyAnim/LN1"); left[1] = Resources.Load <Sprite>("EnemyAnim/LN2"); left[2] = Resources.Load <Sprite>("EnemyAnim/LN3"); left[3] = Resources.Load <Sprite>("EnemyAnim/LN4"); left[4] = Resources.Load <Sprite>("EnemyAnim/LN5"); left[5] = Resources.Load <Sprite>("EnemyAnim/LY1"); left[6] = Resources.Load <Sprite>("EnemyAnim/LY2"); left[7] = Resources.Load <Sprite>("EnemyAnim/LY3"); left[8] = Resources.Load <Sprite>("EnemyAnim/LY4"); left[9] = Resources.Load <Sprite>("EnemyAnim/LY5"); StartCoroutine(Walk()); canSeePlayer = false; }
// Update is called once per frame void Update() { if (coList.Count != 0) { parent.numAlliesNear = coList.Count; alliesNeedHeal = false; foreach (GameObject x in coList) { damageController xdc = x.GetComponent <damageController>(); if (xdc.getHealth() < xdc.getMaxHealth()) { alliesNeedHeal = true; } } if (alliesNeedHeal) { if (!parent.wait && !parent.isHealing) { parent.wait = true; StartCoroutine(parent.Heal()); //GetComponent<SpriteRenderer>().enabled = true; } } else { if (!parent.wait && parent.isHealing) { parent.wait = true; StartCoroutine(parent.Move()); //GetComponent<SpriteRenderer>().enabled = false; } } } else { parent.numAlliesNear = 0; } if (parent.isHealing) { secondCount += healFactor * Time.deltaTime; if (secondCount >= 1f) { secondCount -= 1f; foreach (GameObject x in coList) { x.GetComponent <damageController>().giveHealth(1); } } if (!parent.wait) { } frameCount++; if (frameCount == 9) { var clone1 = Instantiate(gas1, transform.position, Quaternion.identity); } else if (frameCount >= 18) { frameCount = 0; var clone2 = Instantiate(gas2, transform.position, Quaternion.identity); } } else { moveLoc = new Vector3(0f, 0f, 0f); foreach (GameObject x in coList) { moveLoc += x.transform.position; } moveLoc /= coList.Count; if (coList.Count != 0) { parent.MoveTo(moveLoc); } else { parent.RunAway(); } } }