void GenerateDragonSlayer(int playerIdx, int slayerScore) { if (slayerScore == 0) { Debug.LogWarning("slayerScore分数不能为0"); return; } FishGenerator fishGenrator = GameMain.Singleton.FishGenerator; Player p = GameMain.Singleton.PlayersBatterys[playerIdx]; Transform tsPlayer = p.transform; Fish dragonSlayer = Instantiate(Prefab_DragonSlayer) as Fish; Transform tsDragonSlayer = dragonSlayer.transform; tsDragonSlayer.parent = fishGenrator.transform;//以fishGenerator作为父节点,过场时可以删除 tsDragonSlayer.position = tsPlayer.position; tsDragonSlayer.rotation = tsPlayer.rotation * Quaternion.Euler(0F, 0F, 90f); Vector3 tmpPos = tsDragonSlayer.localPosition; tmpPos.z = -3.1F; tsDragonSlayer.localPosition = tmpPos; dragonSlayer.swimmer.Go(); FishEx_DragonSlayer fishExDragonSlayer = dragonSlayer.GetComponentInChildren <FishEx_DragonSlayer>(); if (fishExDragonSlayer != null) { fishExDragonSlayer.Owner = p; fishExDragonSlayer.Creator = this; //效果:设置显示玩家 Transform tsTextPlayerId = fishExDragonSlayer.transform.FindChild("TextPlayerId"); if (tsTextPlayerId != null) { tk2dTextMesh textPlayerID = tsTextPlayerId.GetComponent <tk2dTextMesh>(); textPlayerID.text = (p.Idx + 1).ToString(); textPlayerID.Commit(); } else { YxDebug.LogError("需要在fishDragonSlayer对象下放入tk2dtextmesh:TextPlayerId"); } } else { YxDebug.LogError("屠龙刀在子gameobject必须包含 fishExDragonSlayer."); } }
/// <summary> /// 由FishEx_DragonSlayer回调(减少事件订阅消耗) /// </summary> /// <param name="ds"></param> /// <param name="owner"></param> public void On_FishExDragonSlayerTouchFish(FishEx_DragonSlayer ds, Fish fishTouched, Player owner) { //接触到的fish已经死亡 if (fishTouched == null || !fishTouched.Attackable) { return; } if (!mSlayFishCache.ContainsKey(fishTouched.TypeIndex)) { return; } //*为了调用函数创建一个临时的bullet,非常呕心,但是没办法,因为很多地方使用这个变量.以后需要注意事件,公用函数的写法 GameObject tmpBulletGo = new GameObject(); Bullet b = tmpBulletGo.AddComponent <Bullet>(); b.FishOddsMulti = 1; b.Score = DragonSlayerScores[owner.Idx].Val; fishTouched.Kill(owner, b.Score, fishTouched.Odds * b.FishOddsMulti, b.FishOddsMulti, 0F, 0); owner.GainScore(fishTouched.Odds * DragonSlayerScores[owner.Idx].Val , fishTouched.Odds , DragonSlayerScores[owner.Idx].Val ); //删除之前创建的 Destroy(tmpBulletGo); //dragonSlayerScore归零 DragonSlayerScores[owner.Idx].Val = 0; //删除dragonSlayer ds.Clear(); //出现效果 GameObject efGo = Instantiate(Ef_DragonKilled) as GameObject; Vector3 worldPos = fishTouched.transform.position; worldPos.z = Defines.GlobleDepth_BombParticle; efGo.transform.position = worldPos; }