protected void OnTriggerEnter(Collider c) { if (c.gameObject.layer == k_CoinsLayerIndex) { if (magnetCoins.Contains(c.gameObject)) { magnetCoins.Remove(c.gameObject); } if (c.GetComponent <Coin>().isPremium) { Addressables.ReleaseInstance(c.gameObject); GameSensor.instance.SendEvent("premium"); PlayerData.instance.premium += 1; controller.premium += 1; m_Audio.PlayOneShot(premiumSound); } else { Coin.coinPool.Free(c.gameObject); PlayerData.instance.coins += 1; controller.coins += 1; m_Audio.PlayOneShot(coinSound); } } else if (c.gameObject.layer == k_ObstacleLayerIndex) { if (m_Invincible || controller.IsCheatInvincible()) { return; } controller.StopMoving(); c.enabled = false; GameSensor.instance.SendEvent("impact"); Obstacle ob = c.gameObject.GetComponent <Obstacle>(); if (ob != null) { ob.Impacted(); } else { Addressables.ReleaseInstance(c.gameObject); } if (TrackManager.instance.isTutorial) { m_TutorialHitObstacle = true; } else { controller.currentLife -= 1; } controller.character.animator.SetTrigger(s_HitHash); if (controller.currentLife > 0) { m_Audio.PlayOneShot(controller.character.hitSound); SetInvincible(); } // The collision killed the player, record all data to analytics. else { m_Audio.PlayOneShot(controller.character.deathSound); m_DeathData.character = controller.character.characterName; m_DeathData.themeUsed = controller.trackManager.currentTheme.themeName; m_DeathData.obstacleType = ob.GetType().ToString(); m_DeathData.coins = controller.coins; m_DeathData.premium = controller.premium; m_DeathData.score = controller.trackManager.score; m_DeathData.worldDistance = controller.trackManager.worldDistance; } } else if (c.gameObject.layer == k_PowerupLayerIndex) { Consumable consumable = c.GetComponent <Consumable>(); if (consumable != null) { GameSensor.instance.SendEvent("powerup"); controller.UseConsumable(consumable); } } }
protected void OnTriggerEnter(Collider c) { if (c.gameObject.layer == k_CoinsLayerIndex) { if (magnetCoins.Contains(c.gameObject)) { magnetCoins.Remove(c.gameObject); } if (c.GetComponent <Coin>().isDiamond) { Destroy(c.gameObject); controller.diamonds += 1; m_Audio.PlayOneShot(premiumSound); } else { Coin.coinPool.Free(c.gameObject); controller.coins += 1; m_Audio.PlayOneShot(coinSound); } } else if (c.gameObject.layer == k_ObstacleLayerIndex) { if (m_Invincible || controller.IsCheatInvincible()) { return; } controller.StopMoving(); c.enabled = false; //尝试转化为障碍物 Obstacle ob = c.gameObject.GetComponent <Obstacle>(); if (ob != null) { ob.Impacted(); } else { //不是障碍物,则清除(说明是可以吃到的东西) Destroy(c.gameObject); } //撞到障碍物,生命值扣除1 controller.currentLife -= 1; // controller.character.animator.SetTrigger(s_HitHash); //撞到障碍物,有生命值,则扣除一格生命值 if (controller.currentLife > 0) { //播放撞击声音 m_Audio.PlayOneShot(controller.character.hitSound); // SetInvincible(); } else //撞到障碍物后死亡 { m_Audio.PlayOneShot(controller.character.deathSound); m_DeathData.character = controller.character.characterName; m_DeathData.themeUsed = controller.trackManager.currentTheme.themeName; m_DeathData.obstacleType = ob.GetType().ToString(); m_DeathData.coins = controller.coins; m_DeathData.diamonds = controller.diamonds; m_DeathData.score = controller.trackManager.score; m_DeathData.worldDistance = controller.trackManager.worldDistance; } } else if (c.gameObject.layer == k_PowerupLayerIndex) { Consumable consumable = c.GetComponent <Consumable>(); if (consumable != null) { controller.UseConsumable(consumable); } } }
protected void OnTriggerEnter(Collider c) { if (c.gameObject.layer == k_TrashLayerIndex) { Trash trash = c.GetComponent <Trash>(); trash.Dispose(); Compost compost = c.gameObject.GetComponent <Compost>(); Metal metal = c.gameObject.GetComponent <Metal>(); Nuclear nuclear = c.gameObject.GetComponent <Nuclear>(); if (compost != null) { inventory.AddCompost(); } else if (metal != null) { inventory.AddMetal(); } else if (nuclear != null) { inventory.AddNuclear(); } Destroy(c.gameObject); } else if (c.gameObject.layer == k_CoinsLayerIndex) { if (magnetCoins.Contains(c.gameObject)) { magnetCoins.Remove(c.gameObject); } if (c.GetComponent <Coin>().isPremium) { Destroy(c.gameObject); controller.premium += 1; m_Audio.PlayOneShot(premiumSound); } else { /// TODO: Need to use the right pool Coin.coinPools[0].Free(c.gameObject); controller.coins += 1; m_Audio.PlayOneShot(coinSound); } } else if (c.gameObject.layer == k_ObstacleLayerIndex) { if (m_Invincible || controller.IsCheatInvincible()) { return; } controller.StopMoving(); c.enabled = false; Obstacle ob = c.gameObject.GetComponent <Obstacle>(); if (ob != null) { ob.Impacted(); } else { Destroy(c.gameObject); } controller.currentLife -= 1; controller.character.animator.SetTrigger(s_HitHash); if (controller.currentLife > 0) { m_Audio.PlayOneShot(controller.character.hitSound); SetInvincible(); } // The collision killed the player, record all data to analytics. else { m_Audio.PlayOneShot(controller.character.deathSound); m_DeathData.character = controller.character.characterName; m_DeathData.themeUsed = controller.trackManager.currentTheme.themeName; m_DeathData.obstacleType = ob.GetType().ToString(); m_DeathData.coins = controller.coins; m_DeathData.premium = controller.premium; m_DeathData.score = controller.trackManager.score; m_DeathData.worldDistance = controller.trackManager.worldDistance; } } else if (c.gameObject.layer == k_PowerupLayerIndex) { Consumable consumable = c.GetComponent <Consumable>(); if (consumable != null) { controller.UseConsumable(consumable); } } }
protected void OnTriggerEnter(Collider c) { if (c.gameObject.layer == k_CoinsLayerIndex) { if (magnetCoins.Contains(c.gameObject)) { magnetCoins.Remove(c.gameObject); } if (c.GetComponent <Coin>().isPremium) { Destroy(c.gameObject); PlayerData.instance.premium += 1; controller.premium += 1; m_Audio.PlayOneShot(premiumSound); } else { Coin.coinPool.Free(c.gameObject); PlayerData.instance.coins += 1; controller.coins += 1; m_Audio.PlayOneShot(coinSound); } } else if (c.gameObject.layer == k_ObstacleLayerIndex) { if (m_Invincible || controller.IsCheatInvincible()) { if (c.gameObject.tag == "Enemy") { PlayerData.instance.coins += 10; controller.coins += 10; return; } else if (c.gameObject.tag == "Baricada") { sosi.activatedSound = null; controller.powerupSource.Stop(); controller.End("nothing"); m_Armor = false; return; } } controller.StopMoving(); c.enabled = false; Obstacle ob = c.gameObject.GetComponent <Obstacle>(); if (ob != null) { ob.Impacted(); } else { Destroy(c.gameObject); } controller.currentLife -= 1; controller.character.animator.SetTrigger(s_HitHash); if (controller.currentLife > 0) { m_Audio.PlayOneShot(controller.character.hitSound); SetInvincible(); } // The collision killed the player, record all data to analytics. else { m_Audio.PlayOneShot(controller.character.deathSound); m_DeathData.character = controller.character.characterName; m_DeathData.themeUsed = controller.trackManager.currentTheme.themeName; m_DeathData.obstacleType = ob.GetType().ToString(); m_DeathData.coins = controller.coins; m_DeathData.premium = controller.premium; m_DeathData.score = controller.trackManager.score; m_DeathData.worldDistance = controller.trackManager.worldDistance; } } else if (c.gameObject.layer == k_PowerupLayerIndex) { Consumable consumable = c.GetComponent <Consumable>(); if (consumable != null) { controller.UseConsumable(consumable); } } }