void OnTriggerEnter2D(Collider2D other) { if (soundEffects == null) { soundEffects = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <SoundEffectsManager>(); } // Items is for player ultimately. It will be trouble if monster can even pick up the stuff! if (other.tag.Equals("Player")) { // Need to find the inventory again if can't find it! if (playerInventory == null) { Start(); } if (theItemStuff == null) { Start(); } Debug.Log("Interacting with: " + other.name); playerInventory.passInInventory(theItemStuff.m_itemInform); // We also need to give the player back some health! HealthScript zePlayerHealth = other.GetComponent <HealthScript>(); zePlayerHealth.modifyHealth(m_heal); itemInteractParticles.transform.position = transform.position; itemInteractParticles.playEffect(); if (soundEffects != null) { soundEffects.playSound("pickupItems"); } Destroy(gameObject); } }
// Update is called once per frame void Update() { if (soundEffects == null) { soundEffects = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <SoundEffectsManager>(); } if (rb.velocity != Vector2.zero) { if (soundEffects != null) { soundEffects.playSound("movingObj"); } } }
// Update is called once per frame void Update() { if (soundEffects == null) { soundEffects = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <SoundEffectsManager>(); } timeCounter += Time.deltaTime; //Debug.DrawRay(transform.position, directionOfRay * m_range, Color.black); //Debug.Log(gameObject.name + ": " + directionOfRay); if (timeCounter > m_time && heroMeleeAnim != null) { heroMeleeAnim.stopMeleeAttack(); } if (playerIsAttacking) { { // If the player is attacking, then we delay the attack before dealing the damage! m_delayCounter += Time.deltaTime; // If the player is able to attack! if (m_delayCounter > m_delayInitialAttack) { //heroMeleeAnim.stopMeleeAttack(); m_delayCounter = 0; playerIsAttacking = false; Vector3 theBoxPosition = new Vector3(transform.localScale.x * directionOfRay.x, transform.localScale.y * directionOfRay.y); //Debug.Log("Position of Box: " + (transform.position + transform.localScale)); RaycastHit2D[] hits = Physics2D.BoxCastAll(transform.position + theBoxPosition , transform.localScale, 0, Vector2.zero); foreach (RaycastHit2D attacked in hits) { // This is so that it is not attackin itself! if (!attacked.collider.gameObject.Equals(gameObject) && attacked.collider.GetComponent <HealthScript>() != null) { //Debug.Log("Successful attack"); if (soundEffects != null) { soundEffects.playSound("MeleeHit"); } AttackSystemScript.instance.ManageMeleeAttack(this, attacked.collider.GetComponent <HealthScript>()); } } } } } }
public void shootArrow() { if (m_TimeCounter > m_firingRate) { // Well, the player has to stop their movement then they can fire if (soundEffects != null) { soundEffects.playSound("MeleeHit"); } directionOfHero.stopMovement(); isShooting = true; m_TimeCounter = 0; GameObject zeArrow = Instantiate(theArrow); zeArrow.BroadcastMessage("Start"); zeArrow.transform.position = transform.position; zeArrow.BroadcastMessage("setDirection", directionOfHero.directionOfHero); heroAnimator.rangeAttackAnimation(); gameObject.BroadcastMessage("stopMeleeAttack"); MessageSystem.instance.triggerEventCall("RangeAttack"); } }
// This will be used as checking whether it hits the object or not! void OnTriggerEnter2D(Collider2D zeVictim) { // Need to make sure it isn't friendly fire! if (!zeVictim.tag.Equals("Player")) { if (arrowParticleEffect != null) { arrowParticleEffect.transform.position = transform.position; arrowParticleEffect.GetComponent <ParticleScript>().playEffect(); } if (zeVictim.GetComponent <HealthScript>() != null) { AttackSystemScript.instance.ManageArrowAttack(this, zeVictim.GetComponent <HealthScript>()); } if (soundEffects != null) { soundEffects.playSound("RangeHit"); } Destroy(gameObject); //Debug.Log("Hit the " + zeVictim.gameObject.name); } }
public bool checkForCollision() { collision = Physics2D.CircleCastAll(transform.position, circleCollider.bounds.size.x - 0.5f, Vector2.zero, 0); foreach (RaycastHit2D temp in collision) { if (temp.collider != null) { if (temp.collider.gameObject.tag == "Player" && temp.collider.gameObject.GetComponent <HealthScript>() != null) { //if (projectileParticles != null) //{ // projectileParticles.transform.position = transform.position; // projectileParticles.GetComponent<ParticleScript>().playEffect(); //} foreach (GameObject zeGO in rockParticleSystems) { ParticleScript zeParticleEffects = zeGO.GetComponent <ParticleScript>(); // Need to make sure that the particle system is not playing if (!zeParticleEffects.isPlaying()) { zeParticleEffects.transform.position = transform.position; zeParticleEffects.playEffect(); break; } } temp.collider.gameObject.GetComponent <HealthScript>().modifyHealth(-damage); if (soundEffects != null) { soundEffects.playSound("smashing"); } return(true); } else if (temp.collider.gameObject.tag != "GolemBoss" && temp.collider.gameObject.tag != "GolemBoss_Projectile" && temp.collider.gameObject.tag != "Arrows") { //if (projectileParticles != null) //{ // projectileParticles.transform.position = transform.position; // projectileParticles.GetComponent<ParticleScript>().playEffect(); //} foreach (GameObject zeGO in rockParticleSystems) { ParticleScript zeParticleEffects = zeGO.GetComponent <ParticleScript>(); // Need to make sure that the particle system is not playing if (!zeParticleEffects.isPlaying()) { zeParticleEffects.transform.position = transform.position; zeParticleEffects.playEffect(); break; } } if (soundEffects != null) { soundEffects.playSound("smashing"); } //Debug.Log(temp.collider.gameObject.name); return(true); } } } return(false); }