public void OnTriggerEnter2D(Collider2D other) { PlayerScript ps = other.GetComponent<PlayerScript>(); if (ps != null) { if (ps.RateUp < level) { ps.RateUp = level; PlayerAttack pa = other.GetComponent<PlayerAttack>(); switch(level) { case 1: pa.fireRate = 0.25f; break; case 2: pa.fireRate = 0.2f; break; case 3: pa.fireRate = 0.15f; break; } } Destroy(gameObject); } }
void OnTriggerStay2D(Collider2D collider) { if (collider.GetComponent<Damageable>() != null) { collider.GetComponent<Damageable>().TakeDamage(GetComponent<Damager>().damage * Time.deltaTime); } }
void OnTriggerEnter2D(Collider2D other) { // Obstacles and Butter behave the same way, except Obstacles add negative Butter if (other.tag == "Pickup") { Pickup p = other.GetComponent<Pickup>(); if (p.lane == currentLane) { butterMeter.AddButter(p); // Add to score if the pickup has a positive value if (p.butterAmount > 0) { ScoreTracker s = FindObjectOfType<ScoreTracker>(); s.score += (int)(p.butterAmount * 1000); } Destroy(other.gameObject); } } // Dog caught up to the player, Game Over! else if (other.tag == "Dog") { Dog d = other.GetComponent<Dog>(); if( d.currentState != DogState.EATING ) { d.Stop(); eaten = true; stateManager.SetGameState(StateManager.GameplayState.END); } } }
IEnumerator OnTriggerEnter2D(Collider2D col) { if (waitingForShip && col.GetComponent<ShipController>()) { Destroy(col.GetComponent<ShipController>()); var ship = col.transform.root; foreach (var h in ship.GetComponentsInChildren<Hull>()) Destroy(h); yield return new WaitForSeconds(1); Destroy(ship.rigidbody2D); foreach (var c in ship.GetComponentsInChildren<Collider2D>()) Destroy(c); ship.parent = transform; transform.root.collider2D.isTrigger = true; var hover = transform.root.GetComponent<MotherShipHover>(); foreach (Transform t in ExitPath) { hover.target = t; while (Vector2.Distance(transform.root.position, t.position) > 1) { yield return new WaitForFixedUpdate(); } } //Destroy(transform.root.gameObject); } }
void OnTriggerStay2D(Collider2D coll) { if (coll.transform.tag == "Object" && coll.GetComponent<MovableObject>() != null) { bool isOnRightSide = coll.transform.position.x > transform.position.x; if (isRightHeading == isOnRightSide && coll.gameObject.GetComponent<MovableObject>().weight <= maxWeight) { pushingObject = coll.gameObject; // Debug.Log("Pushing!!!"); } if (pushingObject!= null) { MovableObject target = pushingObject.GetComponent<MovableObject>(); if (target.pusher != null) return; target.pusher = gameObject; isPushing = true; } } else if (coll.GetComponent<Water>()!=null) { Collider2D body = GetComponents<Collider2D>().First(c=>!c.isTrigger); float tall = body.bounds.size.y; float sink = Mathf.Clamp(coll.bounds.max.y - body.bounds.min.y,0,tall); float buoyancy = sink/tall*GetComponent<Rigidbody2D>().gravityScale*Physics2D.gravity.y; GetComponent<Rigidbody2D>().AddForce(Vector2.down * buoyancy * GetComponent<Rigidbody2D>().mass, ForceMode2D.Force); //GetComponent<Rigidbody2D>().velocity = GetComponent<Rigidbody2D>().velocity * 0.99f; } }
void OnTriggerEnter2D(Collider2D other) { // If player collided with item Sword if (other.tag == "Player") { stat=other.GetComponent<StatCollectionClass>(); Up = other.GetComponent<ItemUpgrade>(); Destroy(this.gameObject); // set item sword unlocked stat.itemSword = true; Up.SwordLevel++; Up.SwordDamage+=100f; //if no equipment now just equip sword to player if(stat.ArmorEquip==false &&stat.BowEquip==false) { //add player attack damage with SwordDamage stat.damage+=Up.SwordDamage; //set sword equip to true stat.SwordEquip= true; } } // Destroy the item }
void OnTriggerStay2D(Collider2D other) { if (other.gameObject.layer == LayerMask.NameToLayer("Pickup")) { Rigidbody2D partBody = other.GetComponent<Rigidbody2D>(); Transform partCenter = other.transform.GetChild(1); float magnitude = 0; if(this.transform.position.x >= partCenter.position.x) { magnitude = -25f; } else { magnitude = 25f; } partBody.AddForce(new Vector2(magnitude, 0), ForceMode2D.Force); } if (other.gameObject.layer == LayerMask.NameToLayer("Player")) { Rigidbody2D playerBody = other.GetComponent<Rigidbody2D>(); Transform partCenter = other.transform.GetChild(1); float magnitude = 0; if(this.transform.position.x >= partCenter.position.x) { magnitude = -100f; } else { magnitude = 100f; } playerBody.AddForce(new Vector2(magnitude, 0), ForceMode2D.Force); } }
private void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision.CompareTag("Glass")) { collision.GetComponent <ForGlassAnimat>().Break(); if (bloodSlider.value > 0) { bloodSlider.value -= 10; } // bloodSlider.value } else if (collision.CompareTag("Player")) { if (collision.name == "Player_1") { var rig = GetComponent <Rigidbody2D>(); //高速心扣血 if (rig.velocity.magnitude >= 13) { collision.GetComponent <Player1Life>().TakeDamage(); } return; } heartCount++; //Debug.Log("Character Name: "+MainCharacter.Instance.name); if (MainCharacter.Instance.isDashing == false) { //击退和击飞 switch (collision.name) { case "Foot": //print("jumpUp"); MainCharacter.Instance._playerVelocityY += collision.transform.localScale.x * sizeToJumpHeightRate; //MainCharacter.Instance._playerVelocityY = // Mathf.Min(MainCharacter.Instance._playerVelocityY, maxYSpeed); print("hit foot, final vertical speed: " + MainCharacter.Instance._playerVelocityY); //MainCharacter.Instance._canJump = 2; break; case "Body": // print("hitBack"); MainCharacter.Instance._playerVelocityX -= collision.transform.localScale.x * sizeToHitBackSpeedRate * hitBackSpeed; print("hit body, final horizontal speed: " + MainCharacter.Instance._playerVelocityX); break; } } PoolManager.RecycleHeart(this.gameObject); } }
void OnTriggerEnter2D(Collider2D coll) { if (coll.GetComponent <Actor>()) { if(coll.gameObject != activator && !coll.transform.IsChildOf(activator.transform)) { print (coll.gameObject.name + " colliding with" + gameObject.name); if (knockback > 0){ coll.GetComponent<Actor> ().isKnockedBack = true; coll.GetComponent<Rigidbody2D> ().AddForce (new Vector2 (activator.GetComponent<Fighter> ().facing * knockback, knockback), ForceMode2D.Impulse); } coll.gameObject.SendMessage("Damage", damage); activator.GetComponent<Fighter>().dPause(); activator.GetComponent<Fighter>().ShakeFunction(coll.gameObject, damage); activator.GetComponent<Fighter>().PlaySound(hitSound, activator.GetComponent<Fighter>().SFX); if(this.name == "HitBox_Heavy" && coll.GetComponent<Fighter>().stars>0){ coll.gameObject.GetComponent<Fighter>().StarLoss(); if(activator.GetComponent<Fighter>().stars<activator.GetComponent<Fighter>().starMax){ activator.GetComponent<Fighter>().stars++; } } if(coll.GetComponent <Fighter>()) { coll.gameObject.SendMessage("ArmorDamage", armorbreak); } } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { other.GetComponent<Health>().TakeDamage(damage); Debug.Log(other.GetComponent<Character>().id); } }
void OnTriggerStay2D(Collider2D other) { if (other.GetComponent<PhysicsRoom> () != null) { Vector3 wind = other.GetComponent<PhysicsRoom> ().velocity; this.windSpeed += new Vector2 (wind.x, wind.y); } }
void OnTriggerEnter2D(Collider2D collider) { if(collider.GetComponent<Damageable>() != null) { collider.GetComponent<Damageable>().TakeDamage(GetComponent<Damager>().damage); } }
void OnTriggerStay2D(Collider2D other) { if (other.GetComponent<Collectables>() && Input.GetButtonDown("Action Player "+ playerString)) { other.GetComponent<Collectables>().Collected(); if (other.tag == "Pills") { if (GetComponent<PlayerGetPills>()) GetComponent<PlayerGetPills>().GotIt(); audioSource.PlayOneShot (collectableSFX); } if (other.tag == "Crown") { if (GetComponent<PlayerGetCrown>()) GetComponent<PlayerGetCrown>().GotIt(); audioSource.PlayOneShot (collectableSFX); } if (other.tag == "Piece") { if (GetComponent<PlayerCollectPiece>()) GetComponent<PlayerCollectPiece>().GotIt(); audioSource.PlayOneShot (collectableSFX); } } }
public void OnTriggerEnter2D(Collider2D collision) { if (sideCheck (collision.transform.position) && !localObjects.ContainsKey (collision.gameObject)) { GameObject cobj = collision.gameObject; string ctag = cobj.tag; if (!localObjects.ContainsKey (cobj) && (ctag == "Player" || ctag == "Enemy")) { GameObject clone = Instantiate ( cobj, (Vector2)cobj.transform.position + offset, cobj.transform.rotation ) as GameObject; localObjects.Add (cobj, clone); localObjects.Add (clone, cobj); var clRigid = clone.GetComponent<Rigidbody2D> (); var clGrav = clone.GetComponent<CardinalGravity2D> (); clRigid.velocity = VecRotate (collision.GetComponent<Rigidbody2D> ().velocity); clRigid.angularVelocity = collision.GetComponent<Rigidbody2D> ().angularVelocity; clGrav.GravDirection = (Direction)(((int)clGrav.GravDirection + (int)turnToPaired) % 4); clone.transform.RotateAround (pair.transform.position, Vector3.forward, (int)turnToPaired * 90); /*clone.transform.rotation = Quaternion.Euler ( 0, 0, 90 * (int)turnToPaired + clone.transform.rotation.eulerAngles.z );*/ } } }
void OnTriggerEnter2D(Collider2D other) { if(other.GetComponent<ArenaOpponent>()!=null) { other.GetComponent<ArenaOpponent>().mAmmoRemaining = 3+PlayerPrefs.GetInt("ArenaRound"); } }
void OnTriggerEnter2D (Collider2D collider) { Debug.Log("Projectile hit something"); var unit = collider.GetComponent<UnitBase>(); var proj = collider.GetComponent<Projectile>(); if (unit != null){ if (unit == shooter) { Debug.Log("Ignoring projectile trigger, as bullet touches the shooter"); return; } if (unit.teamID == shooter.teamID) { Debug.Log("Ignoring projectile trigger, as friendly fire is disabled"); return; } unit.ProjectileHit(this); // Destroy projectile after hit Explode(); } else if (proj != null) { // If projectile hits projectile //Explode(); } else { // Destroy projectile on any hit Explode(); // todo: some projectiles that can go through items? } }
void OnTriggerEnter2D(Collider2D coll) { if (coll.gameObject.tag == "Player") { Destroy(this.gameObject); playerAttack = coll.GetComponent<PlayerAttackScript>(); playerAudioSource = coll.GetComponent<AudioSource>(); playerAudioSource.PlayOneShot(playerAttack.pickUpSound); if (thisPower == "Freeze") { playerAttack.freezePowerReady = true; } else if (thisPower == "Wind") { playerAttack.windPowerReady = true; } else if (thisPower == "Speed") { playerAttack.speedPowerReady = true; } else if (thisPower == "Shield") { playerAttack.shieldPowerReady = true; } } }
public void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent<GiveDamageToPlayer>() != null) // break with + no points (for fire) { // Debug.Log("There goes the balloon"); if (BaloonBurstSound != null) AudioSource.PlayClipAtPoint(BaloonBurstSound, transform.position, 0.4f); Instantiate(balloonBurst, transform.position, transform.rotation); // Create the Floating text FloatingText.Show(string.Format("POP"), "PointsText", new FromWorldPointTextPositioner(Camera.main, transform.position, 1.5f, 50)); // We only want the ballons once per level Destroy(gameObject); } else { if (other.GetComponent<SimpleProjectile>() == null) // Exit when not knife return; if (BaloonBurstSound != null) AudioSource.PlayClipAtPoint(BaloonBurstSound, transform.position, 0.4f); GameManager.Instance.AddPoints(PointsToAdd); GameManager.Instance.AddBalloon(1); Instantiate(balloonBurst, transform.position, transform.rotation); // Create the Floating text FloatingText.Show(string.Format("POP"), "PointsText", new FromWorldPointTextPositioner(Camera.main, transform.position, 1.5f, 50)); // We only want the ballons once per level Destroy(gameObject); } }
void OnTriggerEnter2D(Collider2D coll) { if (coll.gameObject.tag == "Enemy") { if (GetComponentInParent<PlayerSkills>().cTouch) { if (coll.name == "RangedEnemy") { coll.GetComponent<RangedEnemy>().frozen = true; } if (coll.name == "Boss") { print("lol cant freeze"); } else { coll.GetComponent<Enemy>().frozen = true; } } if (GetComponentInParent<PlayerSkills>().heroicStr) coll.transform.gameObject.GetComponent<Health>().currentHealth -= 20; else{ coll.transform.gameObject.GetComponent<Health>().currentHealth -= 10; } } }
void OnTriggerEnter2D(Collider2D other) { if(gameObject.name == "Sasuke" && sasuke.isChargingChidori) { if(!sasuke.chidoriStrike) { if(other.GetComponent<Rigidbody2D>() != null) { playerRigidBody = other.GetComponent<Rigidbody2D>(); } if(other.gameObject != null) { if (other.transform.position.x < transform.position.x) { if(playerRigidBody == null) { return; } else { playerRigidBody.velocity = new Vector2(-12.0f, 12.0f); } } else { playerRigidBody.velocity = new Vector2(12.0f, 12.0f); } } sasuke.chidoriStrike = true; } } }
void OnTriggerEnter2D(Collider2D otherCollider) { // Это выстрел? ShotScript shot = otherCollider.gameObject.GetComponent<ShotScript>(); if (shot != null) { // Избегайте дружественного огня if (shot.isEnemyShot != isEnemy) { Damage(shot.damage); // Уничтожить выстрел if (otherCollider.gameObject.tag != "Stone" && otherCollider.gameObject.tag != "Enemy") { Destroy(shot.gameObject); // Всегда цельтесь в игровой объект, иначе вы просто удалите скрипт. } } if(otherCollider.gameObject.tag == "Enemy" ) { otherCollider.GetComponent<Animator>().SetBool("Die", true); otherCollider.GetComponent<Animator>().SetBool("Run", false); Destroy(gameObject, 10f); } } } }
void OnTriggerEnter2D(Collider2D other_go) { if (other_go.tag == "LightSwitch") { touchingLightSwitch = true; lightSwitch = other_go.gameObject; } else if (other_go.tag == "Ladder") { touchingLadder = true; ladder = other_go.gameObject; } else if (other_go.tag == "HiddenPlatform") { other_go.gameObject.GetComponent<HiddenPlatform> ().ShowSprite (true); } else if (other_go.tag == "Door") { other_go.GetComponent<Animator> ().SetBool ("doorIsOpen", true); } else if (other_go.tag == "TriggerDoor") { other_go.GetComponent<FadeInFadeOut> ().fadeOut = true; } else if (other_go.tag == "TriggerVaisseau") { touchingVaisseau = true; vaisseau = other_go.gameObject; } else if (other_go.tag == "HidingElement") { other_go.gameObject.GetComponent<DisappearingElement>().ShowSprite(true); } else if (other_go.tag == "Dialogue") { Debug.Log("test"); other_go.gameObject.GetComponent<DialogTrigger>().ShowSprite(true); } }
void HitTarget(Collider2D collider) { hitCount++; WeaponController.Get.CurrentWeapon.DestroyedTarget(); GameController.Get.SpawnExplosion(collider.transform); if (collider.tag == "Asteroid") { CheckAsteroidType(collider.GetComponent<StandardAsteroid>().Type); GameController.Get.DestroyGameObject(collider.gameObject, collider.GetComponent<StandardAsteroid>().PointsForDestroying); } else { GameController.Get.DestroyGameObject(collider.gameObject, collider.GetComponent<BasicEnemyController>().PointsForDestroying); } if (hitCount >= maxHitCount) { GameController.Get.DestroyProjectile(gameObject, true); } AudioController.Get.PlayWeaponHit(); }
private Vector2 _startPosition; // the initial spawn position of this GameObject #endregion Fields #region Methods /* * @param other, the other GameObject colliding with this GameObject * Function that handles what happens on collision. */ public void OnTriggerEnter2D(Collider2D other) { // Does nothing if other is not a projectile if (other.GetComponent<Projectile>() == null) return; // If other is an instance of a SimpleProjectile var projectile = other.GetComponent<SimpleProjectile>(); // Checks to see if the owner of the projectile is the player if (projectile != null && projectile.Owner.GetComponent<Player>() != null) { // Handles projectile effects if (ProjectileSpawnEffect != null) Instantiate(ProjectileSpawnEffect, ProjectileFireLocation.transform.position, ProjectileFireLocation.transform.rotation); // Sound if (BlockProjectileSound != null) AudioSource.PlayClipAtPoint(BlockProjectileSound, transform.position); DestroyObject(other); // destroys the projectile // Instantiates the projectile, and initilializes the speed, and direction of the projectile projectile = (SimpleProjectile)Instantiate(Projectile, ProjectileFireLocation.position, ProjectileFireLocation.rotation); projectile.Initialize(gameObject, _direction, _controller.Velocity); } }
void OnTriggerEnter2D(Collider2D other) { if(!(gameObject.tag == "eShot" && other.gameObject.tag == "enemy") && !(gameObject.tag == "pShot" && other.gameObject.tag == "player") && gameObject.tag != other.gameObject.tag){ //If this shot is a pShot and hits an enemy if (gameObject.tag == "pShot" && other.gameObject.tag == "enemy") { other.GetComponent<eScript> ().health -= bulletDmg; } //If this shot is an eShot and hits a player else if (gameObject.tag == "eShot" && other.gameObject.tag == "player") { other.GetComponent<pScript> ().health -= bulletDmg; } //If this shot hits a wall else if (other.gameObject.tag == "wall") { Destroy (gameObject); } //If this bullet hits anything, always decrement its health bulletHealth--; //If the bullet has no health, destroy it if (bulletHealth <= 0) Destroy (gameObject); } }
/// <summary> /// Causes damage to any collided object (if appropriate) /// </summary> /// <param name="collider">Collided object</param> // [Server] void OnTriggerEnter2D(Collider2D collider) { if (!base.isServer) return; SpaceshipController ship = collider.GetComponent<SpaceshipController> (); if (ship != null && (ship.GetId () == this.id || ship.GetId () == 0)) { Debug.Log("Avoided collision between " + ship.GetId() + " and " + this.id); return; } if (ship!=null) { Debug.Log("Shot Collision with: " + collider + "(" + ship.GetId() + ", " + this.id + ")"); } HealthSystem healthSystem = collider.GetComponent<HealthSystem>(); if(healthSystem != null && isServer){ healthSystem.DamageHealth(this.damage); } // TODO: BETTER EXCEPTION METHOD FOR BLACKHOLES if (collider.GetComponent<BlackHoleBehaviour> () != null) { return; } SpaceStationController st = collider.GetComponent<SpaceStationController> (); if (st != null && this.id == st.id) { return; } MakeExplosion(this.transform.position, this.transform.rotation); Destroy(this.gameObject); }
void OnTriggerStay2D( Collider2D activator ) { if ( ( activator.GetComponent<Killable>() != null ) && (GameObject.FindGameObjectWithTag ("Player")) ) { activator.GetComponent<Killable>().Hurt( damage ); } }
/// <summary> /// Raises the trigger enter2 d event. /// </summary> /// <param name="collision">Collision.</param> void OnTriggerEnter2D(Collider2D collision) { //What did we collide with? if(collision.tag == "Player") { //Does the player have return damage? D: if(collision.GetComponent<Player>().HasReturnDamage) { //Stop hitting yourself.. this.gameObject.transform.parent.gameObject.GetComponent<Enemy>().Health -= this.gameObject.transform.parent.gameObject.GetComponent<Enemy>().Damage; collision.GetComponent<Player>().HasReturnDamage = false; } else { //Oh hurt em collision.GetComponent<Player>().TakeDamage(this.gameObject.transform.parent.gameObject.GetComponent<Enemy>().Damage); } //Destroy the game object Destroy(this.gameObject); } if(collision.tag == "LevelBounds") { //Just destroy it Destroy (this.gameObject); } }
void OnTriggerEnter2D(Collider2D collis) { if (collis.gameObject.tag == "wall") { } if (collis.gameObject.tag == "enemy") { EnemyController enemyHealth = collis.GetComponent<EnemyController>(); enemyHealth.wasHit = true; Vector3 targetPosition = collis.transform.position - this.transform.position; targetPosition.z = 0; if (enemyHealth.currentHealth > 0) { collis.transform.GetChild(0).gameObject.SetActive (true); collis.transform.Translate(targetPosition.normalized*2); enemyHealth.TakeDamage (10); } } if (collis.gameObject.tag == "theKing") { KingControl enemyHealth = collis.GetComponent<KingControl>(); Vector3 targetPosition = collis.transform.position - this.transform.position; targetPosition.z = 0; if (enemyHealth.currentHealth > 0) { enemyHealth.TakeDamage(10); } } }
void OnTriggerEnter2D(Collider2D Hit) { if (Hit.GetComponent<Rigidbody2D>() != null && Hit.gameObject.name =="Banana(Clone)") { transform.parent.GetComponent<LiquidBanana>().Splash(transform.position.x, Hit.GetComponent<Rigidbody2D>().velocity.y*Hit.GetComponent<Rigidbody2D>().mass / 40f); Hit.gameObject.GetComponent<SpriteRenderer>().enabled = false; } }
void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent<PlayerManager>()) { if (!player) { player = other.GetComponent<PlayerManager>(); } if(player.GetNumOfCarbons() >= carbonsNeeded) { if (nextLayer == 3) { player.BecomeDiamond(); } else { player.GetComponent<HoldInPlace>().enabled = true; player.GetComponent<FlyTo>().setTarget(transform.position); player.GetComponent<FlyTo>().enabled = true; GameManager.art.SwitchLayer(nextLayer); GameManager.music.moveDownLayer(); } } } }
private void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision.CompareTag("Player")) { collision.GetComponent <PlayerAllinOne>().TakeDamage(gameObject.GetComponentInParent <PangBoss>().damage); } }
private void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision == plrCol) { spr = collision.GetComponent <SpriteRenderer>(); foreach (GameObject Furniture in List1) { Furniture.GetComponent <PolygonCollider2D>().enabled = false; } foreach (GameObject Furniture in List2) { Furniture.GetComponent <PolygonCollider2D>().enabled = true; } uprFlr.SetActive(true); upFlrDOORS.SetActive(true); grdFlr.enabled = false; grdFlrEXTRA.enabled = false; upFlrSPRITES.SetActive(true); spr.sortingOrder = 1; spr.sortingLayerID = SortingLayer.NameToID("1st Floor (items)"); } }
private void OnTriggerExit2D(UnityEngine.Collider2D other) { // 當玩家靠太遠時,無法開始對話(inView = true;) if (other.gameObject.CompareTag("Player")) { other.GetComponent <Controller>().DestroyButton(); inView = false; } }
//======= // 觸發對話 //======= private void OnTriggerEnter2D(UnityEngine.Collider2D other) { // 當玩家靠夠近時,可以開始對話(inView = true;) if (other.gameObject.CompareTag("Player")) { other.GetComponent <Controller>().SpawnButton(); inView = true; } }
private void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision == plrCol) { spr = collision.GetComponent <SpriteRenderer>(); uprFlr.SetActive(true); grdFlr.enabled = false; spr.sortingOrder = 2; } }
protected void OnTriggerEnter2D(UnityEngine.Collider2D other) { if (other.CompareTag("Hostile")) { if (particleEffect) { Instantiate(particleEffect, other.transform.position + new Vector3(0, 2), Quaternion.identity); } var rb = other.GetComponent <Rigidbody2D> (); rb.velocity = Vector2.up * 0.5f * knockbackVelocity; if (movingRight) { rb.velocity += Vector2.right * knockbackVelocity; } else { rb.velocity += Vector2.left * knockbackVelocity; } } }