void OnTriggerEnter2D(Collider2D other) { //Debug.Log(other.gameObject.tag); //Debug.Log(other.gameObject); if (other.gameObject.tag == "Player" && EndLevel) { orb.GetComponent <SpriteRenderer>().color += new Color(0, 0, 0, 0.8f); if (this.gameObject.tag == "Finish") { //Debug.Log(endOfGame.nameOfSound); endOfGame.PlaySound(); } else { endOfLevel.PlaySound(); } completeLevelMenu.SetActive(true); Time.timeScale = 0; } else if (other.gameObject.tag == "Player" && notHit) { //Debug.Log("End?!"); audioCheckPointPassed.PlaySound(); notHit = false; other.gameObject.GetComponent <PlayerCharacterController>().checkPoint = this.gameObject; orb.GetComponent <SpriteRenderer>().color += new Color(0, 0, 0, 0.8f); } }
// Update is called once per frame void Update() { if (enterZone && !switches) { direct = target.transform.position - this.BarrelTurret.transform.position; direct.Normalize(); rotateAmount = Vector3.Cross(direct, this.BarrelTurret.transform.up).z; //angle = Mathf.Atan2(direct.y,direct.x) * Mathf.Rad2Deg; //angle2 = AngleBetweenVector2(this.BarrelTurret.transform.up, direct); //Vector2 vec1Rotated90 = new Vector2(-this.BarrelTurret.transform.up.y, this.BarrelTurret.transform.up.x); //float sign = (Vector2.Dot(vec1Rotated90, direct) < 0) ? -1.0f : 1.0f; //Debug.DrawLine((Vector2)this.BarrelTurret.transform.position, (Vector2)target.transform.position, Color.black, 200f); //Debug.DrawRay((Vector2)this.BarrelTurret.transform.position, direct, Color.red, 200f); //Debug.DrawRay((Vector2)this.BarrelTurret.transform.position, this.BarrelTurret.transform.up, Color.blue, 200f); //Debug.Log(rotateAmount); //Debug.Log(this.BarrelTurret.transform.rotation.eulerAngles); //rotate = Quaternion.AngleAxis(angle,Vector3.forward); //Debug.Log(rotate.eulerAngles); //rotate = Quaternion.AngleAxis(angle2, Vector3.forward); //Debug.Log(rotate.eulerAngles); //Debug.Log(Quaternion.Euler(0,0,this.BarrelTurret.transform.rotation.z + -rotateAmount * speedTurn * Time.deltaTime).eulerAngles); //this.BarrelTurret.transform.rotation = Quaternion.Euler(0, 0, this.BarrelTurret.transform.rotation.z + -rotateAmount * speedTurn * Time.deltaTime); this.BarrelTurret.transform.RotateAround(this.BarrelTurret.transform.position, new Vector3(0f, 0f, 1f), -rotateAmount * speedTurn * Time.deltaTime); //Debug.Log(this.BarrelTurret.transform.rotation.eulerAngles); //this.BarrelTurret.transform.rotation = Quaternion.Slerp(transform.rotation, rotate, -rotateAmount * speedTurn * Time.deltaTime); //Debug.Log(this.BarrelTurret.transform.rotation.eulerAngles); //this.BarrelTurret.transform.RotateAround(this.BarrelTurret.transform.position,new Vector3(0,0,1), -rotateAmount * speedTurn * Time.deltaTime); //this.BarrelTurret.transform.rotation = Quaternion.Euler(0, 0, this.BarrelTurret.transform.rotation.z + sign * speedTurn * Time.deltaTime); //this.transform.rotation = Quaternion.Euler(0,0,Mathf.Clamp(this.transform.rotation.z,0,180)); //withinBounds(230,310); //Debug.Log(sign * speedTurn * Time.deltaTime); //angleOfTurret += sign * speedTurn * Time.deltaTime; //Debug.Log(angleOfTurret); //this.BarrelTurret.transform.rotation = Quaternion.Euler(0,0,angleOfTurret); //Debug.Log(timeStamp); //Debug.Log(Time.time); //Debug.Log(interval); //Debug.Log(withinThreshold(2)); //Debug.Log((Time.time - timeStamp)); //Debug.Log(((Time.time - timeStamp) > interval)); if (withinThreshold(accuracy) && ((Time.time - timeStamp) > rateOfFire)) { timeStamp = Time.time; GameObject bullets = (GameObject)Instantiate(projectile, spawnBullets.position, spawnBullets.rotation); FireSound.PlaySound(); if (this.gameObject.tag == "TinyTurret") { bullets.GetComponent <Projectile>().setLocalScale(); } bullets.GetComponent <Projectile>().hitsGround = projectileHitGround; bullets.GetComponent <Projectile>().speed = SpeedOfProjectile; } } }
void OnTriggerEnter2D(Collider2D other) { switch (other.gameObject.tag) { case "Player": HitSound.PlaySound(); other.gameObject.GetComponent <PlayerCharacterController>().death(); break; case "Enemy": HitSound.PlaySound(); other.gameObject.GetComponent <EnemyController>().death(); break; default: //HitSound.PlaySound(); //Destroy(this.gameObject); break; } }
public void flipSwitch(bool switchOn) { switches = switchOn; if (switchOn == true) { SwitchedOffSound.PlaySound(); } else { //need a "reactivate" sound here? } }
public void death() { Debug.Log("Death"); deathSound.PlaySound(); if (checkPoint == null) { this.transform.position = this.startPosition; } else { this.transform.position = checkPoint.transform.position; } }
void FixedUpdate() { if (climbing || !notDead) { return; } if (Input.GetButton("Jump") && grounded) { grounded = false; rb.AddForce(new Vector2(0f, forceJump)); jumpSound.PlaySound(); grounded = false; } }
void OnTriggerEnter2D(Collider2D other) { //Debug.Log(other.gameObject.tag); switch (other.gameObject.tag) { case "Player": //HitSound.PlaySound(); //This ensures that the projectile won't be obliterated if the player is already dying //if(!(other.gameObject.GetComponent<PlayerCharacterController>().isDying)) //{ other.gameObject.GetComponent <PlayerCharacterController>().death(); Destroy(this.gameObject); //} break; case "Tower": //HitTurret.PlaySound(); //Destroy(this.gameObject); break; case "Ground": HitMetal.PlaySound(); Destroy(this.gameObject); break; case "Rocks": HitMetal.PlaySound(); Destroy(this.gameObject); break; default: //HitSound.PlaySound(); //Destroy(this.gameObject); break; } }
void OnTriggerEnter2D(Collider2D other) { switch (other.gameObject.tag) { case "Player": //HitSound.PlaySound(); break; case "Tower": HitTurret.PlaySound(); Destroy(this.gameObject); break; case "Ground": HitGround.PlaySound(); Destroy(this.gameObject); break; case "Enemy": Debug.Log(other.gameObject.tag); HitGround.PlaySound(); other.gameObject.GetComponent <EnemyController>().hitByRock(); Destroy(this.gameObject); break; case "Shurikens": HitGround.PlaySound(); Destroy(this.gameObject); break; default: //HitSound.PlaySound(); //Destroy(this.gameObject); break; } }
public void death() { if (!Dead) { //Debug.Log("has died"); deathSound.PlaySound(); //isDying = true; state = states.nothing; animate.SetTrigger("Death"); Dead = true; //Destroy(this.gameObject); } //animate.Play("EnemyDeath"); //Destroy(this.gameObject); }
public void leverPulled() { if (OnInputEvent != null) { timeStamp = Time.time; switchesOn = !switchesOn; leverSound.PlaySound(); OnInputEvent.Invoke(switchesOn); Orb.GetComponent <SpriteRenderer>().color = Color.black; } else { Debug.LogWarning("No Turret On Switch"); } }
void onHammerHit() { //Debug.Log("Hit"); if (log != null) { hammerHitLogSound.PlaySound(); log.GetComponent <LogMovement>().fallSounds(); } if (enemy != null) { //Debug.Log("hits1"); //if(Mathf.Sign(enemy.transform.localScale.x) == Mathf.Sign(transform.localScale.x)){ //Debug.Log("hits"); enemy.GetComponent <EnemyController>().death(); //} } }
public void death() { //this if-statement prevents the player being killed while dying :) if (notDead) { deathSound.PlaySound(); animate.SetBool("Climb", false); animate.SetTrigger("Death"); notDead = false; if (climbingwall != null) { //Debug.Log("Wall"); climbingwall.killClimbValues(); climbingwall.objectplayer = null; climbingwall = null; Debug.Log(climbingwall); } climbing = false; rb.gravityScale = 1; } }
void OnTriggerEnter2D(Collider2D other) { switch (other.gameObject.tag) { case "Player": other.gameObject.GetComponent <PlayerCharacterController>().death(); //HitSound.PlaySound(); Destroy(this.gameObject); break; case "Ground": if (hitsGround) { HitGround.PlaySound(); Destroy(this.gameObject); } break; default: //HitSound.PlaySound(); //Destroy(this.gameObject); break; } }
public void fallSounds() { fallSound.PlaySound(); moveLog = true; }
void FixedUpdate() { if (Dead) { return; } if ((state == states.chase) && (rb.velocity.y < -0.01f)) { state = states.nothing; } //Debug.Log(rb.velocity.y); //animate.SetInteger("State",(int)state); temp = this.player.transform.position - this.startpoint.position; temp.Normalize(); RaycastHit2D hit = Physics2D.Raycast(startpoint.position, temp, distance, layerMask); //Physics2D.Linecast(startpoint.position, targetPoint.position,layerMask); Debug.DrawRay(startpoint.position, temp * distance, Color.blue, 1); Debug.DrawRay(startpoint.position, temp * hit.distance, Color.red, 1); if (hit.collider != null) { //Debug.Log(hit.collider.tag); if (hit.collider.tag == "Player" && (state != states.throws && state != states.chase)) { if (hit.collider.gameObject.GetComponent <PlayerCharacterController>().notDead) { hitDistances(hit); spotPlayerSound.PlaySound(); } } else if (hit.collider.tag == "Ground" && (state == states.throws || state == states.chase)) { turnAround(); state = states.patrol; } } else { if (state == states.throws || state == states.chase) { turnAround(); state = states.patrol; } } //Debug.Log(state); switch (state) { case states.idle: rb.velocity = new Vector2(0, 0); if ((Time.time - timeStamp) > turnAroundInterval) { timeStamp = Time.time; turnAround(); state = states.patrol; animate.SetInteger("State", (int)state); } break; case states.chase: turnAroundTarget(); rb.velocity = new Vector2(sign * chaseSpeed * Time.fixedDeltaTime, rb.velocity.y); break; case states.throws: if ((Time.time - timeStamp) > throwInterval) { timeStamp = Time.time; //Debug.Log("Throw"); animate.SetTrigger("throw"); shurikenThrowSound.PlaySound(); } break; case states.patrol: rb.velocity = new Vector2(sign * patrolSpeed * Time.fixedDeltaTime, rb.velocity.y); //Debug.Log(rb.velocity); /* (Mathf.Abs(points[position].transform.position.x - this.transform.position.x) < threshold){ * position = (position + 1) % points.Length; * timeStamp = Time.time; * state = states.idle; * } */ break; } }
void Update() { if (climbing || !notDead) { return; } horizontalMove = Input.GetAxis("Horizontal") * runSpeed * Time.deltaTime; switch (Input.inputString) { case "1": item = Weapons.Hammer; weapon.GetComponent <SpriteRenderer>().sprite = weaponsSprites[0]; //weapon = weaponObjects[0]; OnInputEvent.Invoke(Input.inputString); itemChangeSound.PlaySound(); break; case "2": item = Weapons.Rock; weapon.GetComponent <SpriteRenderer>().sprite = weaponsSprites[1]; //weapon = weaponObjects[1]; OnInputEvent.Invoke(Input.inputString); itemChangeSound.PlaySound(); break; case "3": item = Weapons.Fist; weapon.GetComponent <SpriteRenderer>().sprite = null; //weapon = null; OnInputEvent.Invoke(Input.inputString); itemChangeSound.PlaySound(); break; } if (Mathf.Sign(transform.localScale.x) != Mathf.Sign(horizontalMove) && horizontalMove != 0) { Flip(); } if (Input.GetMouseButtonDown(0) && item == Weapons.Rock) { mouse = (Vector2)mainCamera.ScreenToWorldPoint(Input.mousePosition); animate.SetTrigger("Throw"); rockThrowSound.PlaySound(); } if (Input.GetMouseButtonDown(0) && item == Weapons.Hammer) { animate.SetTrigger("Hammer"); hammerSwingSound.PlaySound(); } if (Input.GetMouseButtonDown(0) && item == Weapons.Fist && climbingwall == null) { animate.SetTrigger("PullLever"); } if (Input.GetMouseButtonDown(0) && item == Weapons.Fist && climbingwall != null && canClimb) { //Debug.Log((Vector2)this.transform.right); //Debug.Log((Vector2)climbingwall.endClimbPoint.transform.position); Vector2 temp = (Vector2)this.transform.position - (Vector2)climbingwall.endMovePoint.transform.position; temp.Normalize(); int sign = (Vector2.Dot((Vector2)this.transform.right, temp) > 0) ? -1 : 1; //Debug.Log((Vector2)this.transform.position - (Vector2)climbingwall.endClimbPoint.transform.position); //Debug.Log((Vector2.Dot((Vector2)this.transform.right, temp) > 0) ? -1 : 1); //Debug.Log(Vector2.Dot(this.transform.right, (Vector2)climbingwall.endClimbPoint.transform.position)); //Debug.Log(sign); //Debug.Log((int)(transform.localScale.x * 10)); if (sign == (int)(transform.localScale.x * 10)) { Debug.Log("Can Climb"); animate.SetBool("Climb", true); rb.velocity = new Vector2(0, 0); rb.gravityScale = 0; climbing = true; climbingwall.climb(this.transform); } else { Debug.Log("Cannot Climb Climb"); } //return; } //Debug.Log(Mathf.Abs(horizontalMove)); rb.velocity = new Vector2(horizontalMove, rb.velocity.y); animate.SetFloat("Horizontal", Mathf.Abs(horizontalMove)); }