/// <summary> /// コライダーと当たった瞬間. /// </summary> /// <param name="other"></param> void OnTriggerEnter2D(Collider2D other) { if (gameObject && other && isDroped && !isDead) { Tadpole tadPole = other.gameObject.GetComponent <Tadpole>(); // ノックバック中は処理しない if (tadPole && !tadPole.CheckKockBack()) { tadPole.LevelUp(); // 餌死亡処理、callbackを呼び出す. isDead = true; if (OnDeadListeners != null) { this.OnDeadListeners(this); } Destroy(gameObject); } } }
void OnTriggerEnter2D(Collider2D other) { if (gameObject && other) { Tadpole otherTadPole = other.gameObject.GetComponent <Tadpole>(); if (otherTadPole) { // ノックバック中は処理しない if (!otherTadPole.CheckKockBack() && !this.CheckKockBack()) { bool bSpawnFood = false; Vector3 spawnPosition = new Vector3(); Tadpole activeTadpole = null; // よりレベルの高い方を下げる // 同レベルの場合は下がらない if (otherTadPole.Level == this.Level) { } else if (otherTadPole.Level < this.Level) { this.LevelDown(); bSpawnFood = true; spawnPosition = this.transform.position; activeTadpole = otherTadPole; } else { otherTadPole.LevelDown(); bSpawnFood = true; spawnPosition = otherTadPole.transform.position; activeTadpole = this; } float popAccel = 0.0f; Vector3 direction = otherTadPole.transform.position - this.transform.position; direction.Normalize(); // ヒットしてきた対象 otherTadPole.SetDirection(direction); otherTadPole.KockBack(); popAccel = (activeTadpole == null)? POP_ACCEL_ACTIVE : ((activeTadpole == otherTadPole)? POP_ACCEL_ACTIVE: POP_ACCEL_PASSIVE); otherTadPole.AddAccel(popAccel, true); // 自分自身 this.SetDirection(-direction); this.KockBack(); popAccel = (activeTadpole == null)? POP_ACCEL_ACTIVE : ((activeTadpole == this)? POP_ACCEL_ACTIVE: POP_ACCEL_PASSIVE); this.AddAccel(popAccel, true); // エサの配置 if (bSpawnFood) { GameObject.Find("GameMain").GetComponent <GameMain>().CreateFood(spawnPosition, false); } } } } }