// Update is called once per frame void Update() { if (targetCollider.IsTouching(upperArmCollider)) { // destroy target on impact Destroy(target); //play paper hit sound effect if (sfx.isPlaying == false) { sfx.Play(); } // make a new target and reassign targetCollider CreateTarget(); targetCollider = target.GetComponent <CircleCollider2D>(); } if (targetCollider.IsTouching(lowerArmCollider)) { // make this proc on both arms just in case Destroy(target); //play paper hit sound effect if (sfx.isPlaying == false) { sfx.Play(); } CreateTarget(); targetCollider = target.GetComponent <CircleCollider2D>(); } }
private void OnTriggerEnter2D(Collider2D target) { if ((target == slash && collider.IsTouching(target)) || (target == thrust && collider.IsTouching(target))) { OnExplode(); } }
// Método para comprobar si el jugador está saltando sobre la llama o no. private void comprobarMuerte() { if (jugador.IsTouching(colliderMuerte)) { GameObject.Destroy(this.gameObject); } }
// Update is called once per frame void Update() { if (Destroycollider.IsTouching(player) && DestroyPlayer == true) { EXDestroy(); } //碰撞到玩家且許可時會消滅 foreach (PolygonCollider2D i in GR.ground) { if (Destroycollider.IsTouching(i) == true) { colliderGround = true; } } //是否碰撞到地板 if (DestroyGround == true && colliderGround == true) { EXDestroy(); } //碰撞地板且許可時消除 foreach (CircleCollider2D i in Explosion) { if (Destroycollider.IsTouching(i) == true) { colliderExplosion = true; } } //是否遇到爆炸 if (DestroyExplosion == true && colliderExplosion == true) { EXDestroy(); --mov.x; } //遇到爆炸且許可時消除 }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag(player_collider.tag) && left_collider.IsTouching(player_collider)) { animator.SetBool("left", true); } else if (other.CompareTag(player_collider.tag) && right_collider.IsTouching(player_collider)) { animator.SetBool("right", true); } }
private void Update() { if (MyCollider.IsTouching(Player.GetCurrentGroundCollider())) { StartCoroutine(SplashWater()); } else if (MyCollider.IsTouching(Player.MyCollider)) { StartCoroutine(HitPlayer()); } }
// Check if player is on top of a pickup block bool IsOnPickUpBlock() { GameObject[] pickups = GameObject.FindGameObjectsWithTag("PickUp"); foreach (GameObject pickup in pickups) { if (groundCollider.IsTouching(pickup.GetComponent <BoxCollider2D>())) { return(true); } } return(false); }
// Update is called once per frame void Update() { if (Input.GetButtonDown("Down") && circle.IsTouching(floor) == true) { floor.enabled = false; // onGround = true; } else if (Input.GetButtonUp("Down") && circle.IsTouching(floor) == false) { floor.enabled = true; } }
void OnTriggerStay2D(Collider2D col) { if (col.CompareTag("Ground") && cc2d.IsTouching(col)) { touchingGround = true; IsJumping = false; } if (col.tag == "Spike" && otherEnemy && !lifes.Invicible) { lifes.TakeDamage(1); otherEnemy = false; } }
void OnTriggerEnter2D(Collider2D other) { if (circleCollider.IsTouching(other)) { if (other.tag == "Player") { projectileController.stopProjectile(); Destroy(gameObject); PlayerHealth playerHealth = other.gameObject.GetComponent <PlayerHealth> (); playerHealth.changeHealth(-damage); } } }
// Update is called once per logic frame void FixedUpdate() { CircleCollider2D playerSoundWaveCC = playerSoundWave.GetComponent <CircleCollider2D>(); CircleCollider2D enemyCC = this.GetComponent <CircleCollider2D>(); Vector2 moveVector; //GameObject[] bottleSoundWaves = GameObject.FindGameObjectsWithTag("tag"); if (enemyCC.IsTouching(playerSoundWaveCC)) { moveVector = transform.position - player.transform.position; this.GetComponent <Rigidbody2D>().velocity = moveVector * -(speed); } else { for (int i = 0; i < navPoints.Length; i++) { BoxCollider2D navPointBC = navPoints[i].GetComponent <BoxCollider2D>(); if (enemyCC.IsTouching(navPointBC)) { timeFree = 30; //print("is touching"); if (i < navPoints.Length - 1) { //print(i + "Not First"); moveVector = transform.position - navPoints[i + 1].transform.position; this.GetComponent <Rigidbody2D>().velocity = moveVector * -(speed - speedMod); return; } else { //print(i + "Go to First"); moveVector = transform.position - navPoints[0].transform.position; this.GetComponent <Rigidbody2D>().velocity = moveVector * -(speed - speedMod); return; } } else { timeFree -= Time.deltaTime; if (timeFree < 0) { //print("out of time"); moveVector = transform.position - navPoints[i].transform.position; this.GetComponent <Rigidbody2D>().velocity = moveVector * -(speed - speedMod); } } } } }
private void OnCollisionEnter2D(Collision2D other) { // Ground check if (other.gameObject.CompareTag("Platform")) { if (!isGrounded) { if (groundCheck.IsTouching(other.collider) && other.GetContact(0).normal.y > 0 && playerState != PlayerStates.Idle) { // Set player to grounded state ChangeState(PlayerStates.Idle); } } } }
}//SetRandomVelocity /// <summary> /// Check if enemy is within the screen/world bounds. /// If not, it probably has not been destroyed yet and is not /// visible to player. Therefore - destroy it. /// </summary> public void SelfDestroy() { if (WorldBounds.Instance == null) return; //No worldbounds instance found. if (_circleCollider.IsTouching(WorldBounds.Instance.Collider)) return; //object still within the bounds this.gameObject.SetActive(false); }//SelfDestroy
void GetLengthToScoreMiddle() { bool isCollidng = myCollider.IsTouching(scoreCollider); if (isCollidng == false) { return; } Debug.Log(isCollidng); Vector2 scoreCenter = scoreCollider.GetComponent <RectTransform>().anchoredPosition; Vector2 mineCenter = GetComponent <RectTransform>().anchoredPosition; Debug.DrawLine(scoreCenter, mineCenter); float length = (scoreCenter - mineCenter).magnitude; float combineRadius = Mathf.Abs(myCollider.radius + scoreCollider.radius); //Debug.Log("Length: " + length + " Radius: " + combineRadius); /*if (length > combineRadius) * { * return; * }*/ Debug.Log("Length: " + length + " combineRadius: " + combineRadius); int scoreAmount = (int)((1 - (length / (scoreCollider.radius * 2))) * 100); Debug.Log(scoreAmount); }
void Update() { if (GameControl.gameStopped != true) { if (cC.IsTouching(ground.GetComponent <BoxCollider2D>())) { jump = true; } else { jump = false; } if (Input.GetKeyDown(KeyCode.UpArrow) && jump && !IsCrouch) { rb.AddForce(new Vector2(0, jumpForce)); } if (Input.GetKeyDown(KeyCode.DownArrow)) { Crouch(); anim.SetBool("Crouch", true); } if (IsCrouch) { if (Input.GetKeyUp(KeyCode.DownArrow)) { Stand(); anim.SetBool("Crouch", false); } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "bullet") { stopMoving = 0; isRotating = false; anim.SetTrigger("Boom"); Destroy(gameObject, 0.5f); source.Play(); } if (collision.tag == "Player") { stopMoving = 0; isRotating = false; anim.SetTrigger("Boom"); source.Play(); } if (area.IsTouching(player.GetComponent <Collider2D>())) { if (!hit) { player.GetComponent <PlayerMovementController>().TakeDamage(damage); } hit = true; Destroy(gameObject, 0.5f); } }
//public void CreateNewPrisoner(Vector3 spawnPosition, int teamNumber) public void CreateNewPrisoner(float xMin, float xMax, float yMin, float yMax, int teamNumber, int teamElementNumber) { Vector3 spawnPosition; RaycastHit2D availablePositionFloor; Collider2D[] circleCollisions; do { spawnPosition = new Vector3(Random.Range(xMin, xMax), Random.Range(yMin, yMax), 0); //// Floor //Debug.DrawRay(new Vector3(spawnPosition.x, spawnPosition.y, 0), Vector3.down * 50f, Color.red); //// Circle //Debug.DrawRay(new Vector3(spawnPosition.x, spawnPosition.y, 0), Vector3.up * (playerPrefab.transform.localScale.y / 2 + 0.5f), Color.yellow); //Debug.DrawRay(new Vector3(spawnPosition.x, spawnPosition.y, 0), Vector3.down * (playerPrefab.transform.localScale.y / 2 + 0.5f), Color.yellow); //Debug.DrawRay(new Vector3(spawnPosition.x, spawnPosition.y, 0), Vector3.left * (playerPrefab.transform.localScale.y / 2 + 0.5f), Color.yellow); //Debug.DrawRay(new Vector3(spawnPosition.x, spawnPosition.y, 0), Vector3.right * (playerPrefab.transform.localScale.y / 2 + 0.5f), Color.yellow); availablePositionFloor = Physics2D.Raycast(spawnPosition, Vector2.down, 50f, whatIsGround); circleCollisions = Physics2D.OverlapCircleAll(spawnPosition, playerPrefab.transform.localScale.y / 2 + 0.5f, whatIsGround); } while (availablePositionFloor.collider == null || circleCollisions.Length > 0); this.teamNumber = teamNumber; this.teamElementNumber = teamElementNumber; SetSpawnerPosition(spawnPosition); circleCollider2D.enabled = true; if (!circleCollider2D.IsTouching(ground.GetComponent <PolygonCollider2D>())) { SpawnPlayer(); } }
private void OnTriggerStay2D(Collider2D collision) { if (collider.IsTouching(collision)) { OnAttack(collision); } }
void FixedUpdate() { if (p1box.IsTouching(pumpu)) { if (!afegir) { //Activa arma loco.activeWeap("arc"); loco2.activeWeap("arc"); afegir = true; } if (!fin) { if (loco.vida <= 0 || loco2.vida <= 0) { if (finuncp) { // final(); if (loco.vida > loco2.vida) { Anarsesala.acabar(true, "bala"); } else { Anarsesala.acabar(false, "bala"); } finuncp = false; } } } } }
void FixedUpdate() //此函式會一直重複執行 { RD.drag = 0.25f; Distance = (Target.transform.position - Mine.position).magnitude; if (Time.time - LastTime > UpdateRate && Distance < Limitdistance) // 距離小於3時開始攻擊 { LastTime = Time.time + Random.value * UpdateRate * 0.5f; StartCoroutine(go()); } //Time.time為遊戲執行的時間,Random.value相當於Random.NextDouble //Time.time - LastTime = { Time.time(末) - Time.time (初) }- Random.value * UpdateRate * 0.5f //故 Time.time(末) - Time.time (初) > UpdateRate * ( 1 + Random.value * 0.5f) // 意即 要過了時間為 更新速率 * (1~1.5) 秒 才會再次更新路徑(使AI不會緊緊跟隨) if (Target == null) { return; } if (Col2D.IsTouching(Target.GetComponent <EdgeCollider2D>())) { RD.drag = 5f; } //碰撞玩家時減速 if (Distance > 1 + Limitdistance) { RD.drag = 5f; StartCoroutine(origin()); } //當過於遠離玩家時,會自發地回到初始位置 }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Enemy" && cc.IsTouching(collision)) { enemiesInRange++; targetEnemy = collision.gameObject; } }
// Update is called once per frame void Update() { if (circle2d.IsTouching(col2d)) { Vector2 sub = player.transform.position - transform.position; player.rotateGravity = Mathf.Atan2(sub.y, sub.x) * Mathf.Rad2Deg - 90; Debug.Log("Sub:" + sub + ", Rot:" + player.rotateGravity); } }
// Employee is actively chasing the player. void Hunt() { if (circle.IsTouching(player.GetComponent <CircleCollider2D>())) { if (!Turn()) { if (turnstep < 1) { Vector3 difference = player.transform.position - gameObject.transform.position; float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg - 90.0f; lastAngle = rotationZ; Quaternion temp = transform.rotation; transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotationZ); } if (turnstep > 0) { //turnstep--; } //if (Turn()) // return; //gameObject.GetComponent<Rigidbody2D>().AddForce(transform.up * speed); //huntsteps = 0; gameObject.GetComponent <Rigidbody2D>().AddForce(transform.up * speed); } else if (turnstep < 3) { //turnstep++; } lastLoc = player.transform.position; } else { circle.enabled = false; currentState = State.lose; } //gameObject.transform.LookAt(new Vector3(player.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z)); }
//等待x秒後刪除物件 // Update is called once per frame void Update() { if (parameter.IsTouching(player)) { texture.enabled = true; anim.enabled = true; RD.velocity = new Vector2(0, 0); StartCoroutine("End"); } }
void HitObject() { m_ObjectToAffect.GetComponentInChildren <LineRenderer>().SetPosition(0, GetDirection() / 2.0f); m_ObjectToAffect.GetComponentInChildren <LineRenderer>().SetPosition(1, GetDirection() * 2.5f); if (Input.GetKeyDown(KeyCode.Space)) { m_ObjectToAffect.GetComponentInChildren <LineRenderer>().enabled = true; StopAllCoroutines(); m_TimeToRotate360 = 10.0f; StartCoroutine(Rotate()); } if (Input.GetKeyUp(KeyCode.Space)) { m_ObjectToAffect.GetComponentInChildren <LineRenderer>().enabled = false; Animator anim = transform.parent.GetComponent <Animator>(); anim.SetTrigger("SpacePressed"); CircleCollider2D mainCircleCollider = m_MiddleOfCircle.GetComponent <CircleCollider2D>(); CircleCollider2D ballCollider = m_ObjectToAffect.GetComponent <CircleCollider2D>(); if (ballCollider.IsTouching(mainCircleCollider)) { StopAllCoroutines(); m_TimeToRotate360 = 5.0f; StartCoroutine(Rotate()); if (m_WaveMovement != null) { m_WaveMovement.GetComponent <SpriteRenderer>().DOFade(0.0f, 0.5f); Destroy(m_WaveMovement, 0.6f); } // instaniate particles m_WaveMovement = Instantiate(m_Prefab, transform.parent, true); m_WaveMovement.transform.rotation = this.transform.rotation; Vector3 tempPos = transform.parent.position; tempPos.y = 2.5f; m_WaveMovement.transform.localPosition = tempPos; m_WaveMovement.transform.parent = null; m_WaveMovement.transform.DOMove(-(m_WaveMovement.transform.localPosition), 1.0f); m_GameManager.AddToScore(); m_HitSound.PlayOneShot(m_HitSound.clip); if (!m_ObjectToAffect.GetComponentInChildren <PlayerController>().GetIsAtEndGoal()) { Rigidbody2D rb = m_ObjectToAffect.GetComponent <Rigidbody2D>(); rb.velocity = Vector3.zero; rb.AddForce(GetDirection() * m_Speed); } } } }
// Checks whether this bool is touching another node. public bool IsTouching(NumberNode otherNode) { if (otherNode != null) { if (circleCollider.IsTouching(otherNode.circleCollider)) { return(true); } } return(false); }
// Update is called once per frame void Update() { if (Input.GetButtonDown("Light") && player.IsTouching(lamp) == true) { light.enabled = true; } /* else if (Input.GetButtonDown("Light") && player.IsTouching(lamp) == false) { * light.enabled = false; * } * else if (Input.GetButtonDown("Light") && player.IsTouching(lamp) == false) * { * * }*/ if (Input.GetButtonDown("Light") && player.IsTouching(lamp) == true && lamp.enabled == true) { GameStates.Instance.IncreaseScore(1); lamp.enabled = false; } }
void OnCollisionEnter2D(Collision2D collision) { collisionSpeed = collision.relativeVelocity.magnitude; if (collision.relativeVelocity.magnitude > maxVelocityForLanding || shipBodyCollider.IsTouching(collision.collider)) { Die(); } if (shipBaseCollider.IsTouching(collision.collider)) { landed = true; } }
private void OnTriggerEnter2D(Collider2D collision) { if (deathCircle.IsTouching(FindObjectOfType <Player>().myBodyCollider)) { if (FindObjectOfType <Player>().vulnerability) { FindObjectOfType <Player>().PlayerInjured(); Debug.Log("Injure Player"); DestroyProjectile(); } } }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.LeftArrow)) { transform.Translate(Vector3.left * runSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.RightArrow)) { transform.Translate(Vector3.right * runSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.UpArrow)) { transform.Translate(Vector3.up * runSpeed * Time.deltaTime); } if (Input.GetKey(KeyCode.DownArrow)) { transform.Translate(Vector3.down * runSpeed * Time.deltaTime); } foreach (Image img in walls.GetComponentsInChildren <Image>()) { if (playerCollider.IsTouching(img.GetComponentInChildren <BoxCollider2D>())) { transform.position = new Vector3(-4.5f, 3.8f, 90); GameData.score = (int)(GameData.score * 0.9); score.text = "Score: " + GameData.score; } } if (playerCollider.IsTouching(finish)) { wonPanel.SetActive(true); } if (playerCollider.IsTouching(gold.GetComponent <CircleCollider2D>())) { GameData.score = GameData.score * 2; score.text = "Score: " + GameData.score; gold.SetActive(false); } }