public void EquipGun(GunType gun) { prevEquippedGunIndex = equippedGunIndex; equippedGunIndex = (int)gun; if (gun != GunType.none) { ShowAmmoInfo(); ArsenalItem new_item = arsenal[(int)gun]; if (new_item.isInArsenal) { Gun old_gun = equippedGun; equippedGun = new_item._gun; //Swap which game objects are active if (old_gun != null) { old_gun.gameObject.SetActive(false); } equippedGun.gameObject.SetActive(true); uiGunIcon.sprite = equippedGun.gunData.gun_sprite; } else { Debug.Log(gun.ToString() + " was not in arsenal."); EquipGun(GunType.none); } } else { if (equippedGun != null) { equippedGun.gameObject.SetActive(false); } HideAmmoInfo(); } }
public override string ToString() { return("GunName" + gunName + "\n" + "AmmoStats:{\n" + "AmmoSize: " + AmmoStats.AmmoSize + "\n" + "CurrentAmmo: " + AmmoStats.CurrentAmmo + "\n" + "DeltaAmmo: " + AmmoStats.DeltaAmmo + "\n" + "AttackRate: " + AttackRate + "\n" + "StartSpeed: " + Powerfull + "\n" + "MinAngle: " + MinAngle + "\n" + "MaxAngle: " + MaxAngle + "\n" + "GunType: " + GunType.ToString() + "\n"); }
public void ReloadGun() { if (Input.GetKeyDown(KeyCode.R) && ActiveItem != null && ActiveItem.GetComponent <Gun>() && ActiveItem.GetComponent <Gun>().Type != GunType.meelee) { //sprawdz typ broni ktora trzymasz GunType HeldWeaponType = ActiveItem.GetComponent <Gun>().Type; //sprawdz czy masz ammo w schowku GameObject MatchedAmmoType = null; foreach (GameObject Item in ItemsList) { if (Item.GetComponent <GunAmmo>()) { if (Item.GetComponent <GunAmmo>().ammoType.ToString() == HeldWeaponType.ToString() && Item.GetComponent <GunAmmo>().ammoAmount > 0) { MatchedAmmoType = Item; //Debug.Log("Mam w ekwipunku odpowiednie ammo w ilości: " + Item.GetComponent<GunAmmo>().ammoAmount); } else { //Debug.Log("Nie mam ammo do tej broni :/"); } } } if (MatchedAmmoType != null && ActiveItem.GetComponent <Gun>().AmmoLoaded < ActiveItem.GetComponent <Gun>().MaxAmmo) { //le potrzeba amunicji żeby na max przeładować guna? int NeededAmmo = ActiveItem.GetComponent <Gun>().MaxAmmo - ActiveItem.GetComponent <Gun>().AmmoLoaded; if (NeededAmmo >= MatchedAmmoType.GetComponent <GunAmmo>().ammoAmount) //Jeśli potrzeba więcej lub równo tego co mamy w kieszeni to wysyłamy gunowi wszystko { ActiveItem.GetComponent <Gun>().Reload(MatchedAmmoType.GetComponent <GunAmmo>().ammoAmount); MatchedAmmoType.GetComponent <GunAmmo>().ammoAmount = 0; } else if (NeededAmmo < MatchedAmmoType.GetComponent <GunAmmo>().ammoAmount) { ActiveItem.GetComponent <Gun>().Reload(ActiveItem.GetComponent <Gun>().MaxAmmo - ActiveItem.GetComponent <Gun>().AmmoLoaded); MatchedAmmoType.GetComponent <GunAmmo>().ammoAmount -= NeededAmmo; } //Debug.Log("Reloaded! pozostało wolnej amunicji" + MatchedAmmoType.GetComponent<GunAmmo>().ammoAmount); AmmoUiText.text = ActiveItem.GetComponent <Gun>().AmmoLoaded.ToString(); if (MatchedAmmoType.GetComponent <GunAmmo>().ammoAmount == 0) { ItemsList.Remove(MatchedAmmoType); Destroy(MatchedAmmoType); } } } }
// Update is called once per frame void Update() { getMenu(); if (hp > 0) { LookTo(); Move(); PlayerAttack(); } else { //人物死亡 isAlive = false; //更换人物的贴图为死亡贴图 GetComponent <SpriteRenderer>().sprite = diedSprite; //将子物体置为不可见 this.gameObject.transform.Find(gunType.ToString()).gameObject.SetActive(false); } }
void CreateAnimator() { string path = EditorUtility.SaveFolderPanel("Save Animator Folder", "", script.gameObject.name); if (string.IsNullOrEmpty(path)) { Debug.Log("Setup canceled"); return; } path += string.Format("/{0}.controller", Gun.gameObject.name); string relativepath = "Assets" + path.Substring(Application.dataPath.Length); string copyName = string.Format("Assets/MFPS/Content/Prefabs/Weapons/Animators/FPWeapon [{0}].controller", gType.ToString()); if (AssetDatabase.CopyAsset(copyName, relativepath)) { AnimatorController controller = AssetDatabase.LoadAssetAtPath(relativepath, typeof(AnimatorController)) as AnimatorController; // Add StateMachines var rootStateMachine = controller.layers[0].stateMachine; ChildAnimatorState s = rootStateMachine.states.ToList().Find(x => x.state.name == "Draw"); s.state.motion = script.DrawName; s = rootStateMachine.states.ToList().Find(x => x.state.name == "Hide"); s.state.motion = script.TakeOut; s = rootStateMachine.states.ToList().Find(x => x.state.name == "Fire"); s.state.motion = script.SoloFireClip; if (gType != GunType.Knife && gType != GunType.Grenade) { s = rootStateMachine.states.ToList().Find(x => x.state.name == "AimFire"); s.state.motion = script.FireAimAnimation; } else { s = rootStateMachine.states.ToList().Find(x => x.state.name == "QuickFire"); s.state.motion = script.QuickFireAnim; } if (gType == GunType.Machinegun || gType == GunType.Pistol || gType == GunType.Burst || gType == GunType.Grenade) { s = rootStateMachine.states.ToList().Find(x => x.state.name == "Reload"); s.state.motion = script.ReloadName; } else if (gType == GunType.Sniper || gType == GunType.Shotgun) { if (!Gun.SplitReloadAnimation) { s = rootStateMachine.states.ToList().Find(x => x.state.name == "Reload"); s.state.motion = script.ReloadName; } else { s = rootStateMachine.states.ToList().Find(x => x.state.name == "StartReload"); s.state.motion = script.StartReloadAnim; s = rootStateMachine.states.ToList().Find(x => x.state.name == "Insert"); s.state.motion = script.InsertAnim; s = rootStateMachine.states.ToList().Find(x => x.state.name == "EndReload"); s.state.motion = script.AfterReloadAnim; } } s = rootStateMachine.states.ToList().Find(x => x.state.name == "Idle"); s.state.motion = script.IdleClip; if (script.AnimatedMovements) { s = rootStateMachine.states.ToList().Find(x => x.state.name == "Walk"); s.state.motion = WalkAnim; s = rootStateMachine.states.ToList().Find(x => x.state.name == "Run"); s.state.motion = RunAnim; } EditorUtility.SetDirty(controller); _animator.runtimeAnimatorController = controller; EditorUtility.SetDirty(_animator); } }
/// <summary> /// 创建子弹 /// </summary> /// <param name="ButtleName">子弹名字</param> /// <param name="Pos">子弹初始位置</param> /// <param name="Rotate">子弹初始旋转</param> /// <param name="Scatte">散射度数</param> /// <param name="ButtleSpeed">子弹速度</param> /// <param name="AttackDistance">子弹飞行距离</param> /// <param name="DemageNums">子弹伤害</param> private void CreateBullet(string ButtleName, Vector3 Pos, Vector3 Rotate, float Scatte, uint ButtleSpeed, float AttackDistance, float DemageNums) { //生成子弹(调整位置与角度) //【判断当前使用左/右手】 GunType currentGunType = m_CurrentLeftGunType; switch (m_CurrentUseGunis) { case UseLeftOrRightGun.LeftGun: currentGunType = m_CurrentLeftGunType; break; case UseLeftOrRightGun.RightGun: currentGunType = RightGunType; break; } //【判断当前是否核心攻击】 string currentBulletName = "Bullet/" + currentGunType + "/" + ButtleName; CoreAttribute currentCoreAttribute = CoreAttribute.Initial; if (m_CurrentBaseCore != null) { switch (m_CurrentBaseCore.Element) { case BaseCore.CoreElement.Primary: currentBulletName = "Bullet/Core/Initial/" + m_CoreBullet[0].name; currentCoreAttribute = CoreAttribute.Initial; break; case BaseCore.CoreElement.Fire: currentBulletName = "Bullet/Core/Fire/" + m_CoreBullet[1].name; currentCoreAttribute = CoreAttribute.Fire; break; case BaseCore.CoreElement.Amethyst: currentBulletName = "Bullet/Core/Amethyst/" + m_CoreBullet[2].name; currentCoreAttribute = CoreAttribute.Amethyst; break; case BaseCore.CoreElement.Ice: currentBulletName = "Bullet/Core/Frozen/" + m_CoreBullet[3].name; currentCoreAttribute = CoreAttribute.Frozen; break; } } //currentBulletName = ButtleName;//敌人子弹测试 GameObject buttleGameObject = ObjectPool.Instance.Spawn(currentBulletName); buttleGameObject.transform.position = Pos; buttleGameObject.transform.rotation = Quaternion.Euler( Rotate + new Vector3(0, 0, Scatte)); //子弹数据填充 Bullet buttle = buttleGameObject.GetComponent <Bullet>(); float currentDeamge = DemageNums * m_CurrentButtleDemagePercent;//伤害比例加成 buttle.BulletStart(ButtleSpeed, AttackDistance, currentDeamge, AllGunCDic[currentGunType].Gun_Data.HardStraight, AllGunCDic[currentGunType].Gun_Data.BeatBack, currentGunType.ToString(), currentCoreAttribute); //更新当前使用左/右手 m_CurrentUseGunis = UseLeftOrRightGun.LeftGun; //当前为火箭系统 if (m_RocketGunState) { UseRocketGun(true); } }
void UpdateUI() { ammoAmountText1.SetText(clipAmonut.ToString() + " / " + ammoAmount.ToString()); firingModeText1.SetText(myGunType.ToString()); }
private void OnGUI() { GUI.Label(new Rect(100, 100, 50, 50), shotType.ToString()); GUI.Label(new Rect(300, 100, 50, 50), gunType.ToString()); }