消防栓重构
This commit is contained in:
parent
7dacbff46c
commit
e1eca313c7
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,7 @@ public class Skill_Pick : MonoBehaviour
|
|||||||
public Animator CharacterAnimator;
|
public Animator CharacterAnimator;
|
||||||
|
|
||||||
public Transform player;
|
public Transform player;
|
||||||
|
public XFS xfs;
|
||||||
private Transform rightHand, leftHand;
|
private Transform rightHand, leftHand;
|
||||||
|
|
||||||
|
|
||||||
@ -59,14 +59,17 @@ public class Skill_Pick : MonoBehaviour
|
|||||||
|
|
||||||
// 禁用物品的碰撞体,防止它与玩家或其他物体碰撞
|
// 禁用物品的碰撞体,防止它与玩家或其他物体碰撞
|
||||||
itemCollider.enabled = false;
|
itemCollider.enabled = false;
|
||||||
|
if (item.transform.name == "gun")
|
||||||
|
{
|
||||||
|
xfs = item.GetComponent<watergun>().Xfs;
|
||||||
|
}
|
||||||
// 将物品设置为玩家手部的子对象,并调整其位置和旋转
|
// 将物品设置为玩家手部的子对象,并调整其位置和旋转
|
||||||
item.transform.SetParent(rightHand, true); // false表示保持物品的世界旋转和位置
|
item.transform.SetParent(rightHand, true); // false表示保持物品的世界旋转和位置
|
||||||
item.transform.localPosition = relativePosition; // 假设玩家手中有一个默认的持物位置
|
item.transform.localPosition = relativePosition; // 假设玩家手中有一个默认的持物位置
|
||||||
item.transform.localRotation = Quaternion.Euler(relativeRotation); // 重置旋转
|
item.transform.localRotation = Quaternion.Euler(relativeRotation); // 重置旋转
|
||||||
|
|
||||||
Destroy(item.GetComponent<Rigidbody>());
|
Destroy(item.GetComponent<Rigidbody>());
|
||||||
|
|
||||||
Debug.Log("^^^^^^^^^^^^^^^^^^^^^^^^^");
|
Debug.Log("^^^^^^^^^^^^^^^^^^^^^^^^^");
|
||||||
// 更新当前持有的物品
|
// 更新当前持有的物品
|
||||||
return item;
|
return item;
|
||||||
@ -98,7 +101,10 @@ public class Skill_Pick : MonoBehaviour
|
|||||||
{
|
{
|
||||||
itemCollider.enabled = true;
|
itemCollider.enabled = true;
|
||||||
}
|
}
|
||||||
|
if (currentItem.transform.name == "gun")
|
||||||
|
{
|
||||||
|
xfs = null;
|
||||||
|
}
|
||||||
currentItem.AddComponent<Rigidbody>();
|
currentItem.AddComponent<Rigidbody>();
|
||||||
|
|
||||||
// 将物品放置在玩家当前位置的地面上
|
// 将物品放置在玩家当前位置的地面上
|
||||||
|
@ -37,6 +37,10 @@ public class Skill_watering : MonoBehaviour
|
|||||||
{
|
{
|
||||||
currentItem.GetComponent<NoFire>().StopFire();
|
currentItem.GetComponent<NoFire>().StopFire();
|
||||||
}
|
}
|
||||||
|
if (currentItem.GetComponent<watergun>() != null)
|
||||||
|
{
|
||||||
|
currentItem.GetComponent<watergun>().water.SetActive(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void StopWateringAnim( )
|
public void StopWateringAnim( )
|
||||||
{
|
{
|
||||||
@ -72,9 +76,9 @@ public class Skill_watering : MonoBehaviour
|
|||||||
currentItem.GetComponent<NoFire>().StartFire();
|
currentItem.GetComponent<NoFire>().StartFire();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentItem.gameObject.name == "gun")
|
if (currentItem.GetComponent<watergun>() != null)
|
||||||
{
|
{
|
||||||
XFS.instance.water.SetActive(true);
|
currentItem.GetComponent<watergun>().water.SetActive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class UseSkill : MonoBehaviour
|
|||||||
// 玩家手中当前持有的物品
|
// 玩家手中当前持有的物品
|
||||||
//[HideInInspector]
|
//[HideInInspector]
|
||||||
public GameObject currentItem = null;
|
public GameObject currentItem = null;
|
||||||
|
public XFS Xfs;
|
||||||
public Skill_Pick _skill_Pick;
|
public Skill_Pick _skill_Pick;
|
||||||
public Skill_Jump _skill_Jump;
|
public Skill_Jump _skill_Jump;
|
||||||
public Skill_watering _skill_Watering;
|
public Skill_watering _skill_Watering;
|
||||||
@ -44,8 +44,8 @@ public class UseSkill : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if(currentItem.gameObject.name=="gun")
|
if(currentItem.gameObject.name=="gun")
|
||||||
{
|
{
|
||||||
float dis= Vector3.Distance(GameObject.Find("player").transform.position, XFS.instance.transform.position);
|
float dis= Vector3.Distance(GameObject.Find("player").transform.position, Xfs.gameObject.transform.position);
|
||||||
if (dis >= 30f)
|
if (dis >= 20f)
|
||||||
{
|
{
|
||||||
|
|
||||||
Drop();
|
Drop();
|
||||||
@ -63,7 +63,7 @@ public class UseSkill : MonoBehaviour
|
|||||||
currentItem = null;
|
currentItem = null;
|
||||||
}
|
}
|
||||||
currentItem = _skill_Pick.Pick();
|
currentItem = _skill_Pick.Pick();
|
||||||
|
Xfs= _skill_Pick.xfs;
|
||||||
if (currentItem.transform.name == "NoFire")
|
if (currentItem.transform.name == "NoFire")
|
||||||
{
|
{
|
||||||
currentItem.transform.Rotate(180f, -80f, -30f);
|
currentItem.transform.Rotate(180f, -80f, -30f);
|
||||||
@ -89,6 +89,7 @@ public class UseSkill : MonoBehaviour
|
|||||||
}
|
}
|
||||||
if (currentItem.transform.name == "gun")
|
if (currentItem.transform.name == "gun")
|
||||||
{
|
{
|
||||||
|
|
||||||
currentItem.transform.rotation = new Quaternion(61.7036781f, 186.325302f, 348.049622f, 0);
|
currentItem.transform.rotation = new Quaternion(61.7036781f, 186.325302f, 348.049622f, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +97,7 @@ public class UseSkill : MonoBehaviour
|
|||||||
public void Drop()
|
public void Drop()
|
||||||
{
|
{
|
||||||
currentItem = _skill_Pick.Drop(currentItem);
|
currentItem = _skill_Pick.Drop(currentItem);
|
||||||
|
Xfs = null;
|
||||||
}
|
}
|
||||||
//拾取
|
//拾取
|
||||||
void Skill_Pick()
|
void Skill_Pick()
|
||||||
@ -109,13 +110,11 @@ public class UseSkill : MonoBehaviour
|
|||||||
|
|
||||||
if(currentItem.transform.name == "NoFire") { currentItem.transform.Rotate(180f, -80f, -30f);
|
if(currentItem.transform.name == "NoFire") { currentItem.transform.Rotate(180f, -80f, -30f);
|
||||||
}
|
}
|
||||||
if (currentItem.transform.name == "gun") { currentItem.transform.rotation = new Quaternion(61.7036781f, 186.325302f, 348.049622f, 0);
|
if (currentItem.transform.name == "gun") {
|
||||||
|
currentItem.transform.rotation = new Quaternion(61.7036781f, 186.325302f, 348.049622f, 0);
|
||||||
|
Xfs = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKeyDown(KeyCode.Q))
|
|
||||||
{
|
|
||||||
currentItem = _skill_Pick.Drop(currentItem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public enum Firestate
|
|||||||
public class Fire : MonoBehaviour
|
public class Fire : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
||||||
private bool isPlayerInRange = false; // 检查玩家是否在范围内
|
public bool isPlayerInRange = false; // 检查玩家是否在范围内
|
||||||
private bool isExtinguishing = false; // 是否正在灭火
|
private bool isExtinguishing = false; // 是否正在灭火
|
||||||
public float extinguishTime = 3f; // 灭火所需的时间
|
public float extinguishTime = 3f; // 灭火所需的时间
|
||||||
private float holdTime = 0f; // 按住按钮的计时
|
private float holdTime = 0f; // 按住按钮的计时
|
||||||
@ -45,10 +45,7 @@ public class Fire : MonoBehaviour
|
|||||||
|
|
||||||
HurtPeople();
|
HurtPeople();
|
||||||
|
|
||||||
if (XFS.instance.IShavewater)
|
|
||||||
{
|
|
||||||
MieFire();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UseSkill == null)
|
if (UseSkill == null)
|
||||||
{
|
{
|
||||||
@ -58,8 +55,8 @@ public class Fire : MonoBehaviour
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(UseSkill.currentItem.transform.name != "NoFire")
|
else if(UseSkill.currentItem.transform.name != "NoFire" && UseSkill.currentItem.transform.name!="gun")
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MieFire();
|
MieFire();
|
||||||
@ -114,6 +111,7 @@ public class Fire : MonoBehaviour
|
|||||||
// // 恢复玩家控制器
|
// // 恢复玩家控制器
|
||||||
// if (!Input.GetMouseButton(0)) EnablePlayerControl();
|
// if (!Input.GetMouseButton(0)) EnablePlayerControl();
|
||||||
//}
|
//}
|
||||||
|
Debug.Log(11111111);
|
||||||
if (isPlayerInRange&& UseSkill.IsWater)
|
if (isPlayerInRange&& UseSkill.IsWater)
|
||||||
{
|
{
|
||||||
// 计算玩家与火源的距离
|
// 计算玩家与火源的距离
|
||||||
@ -135,10 +133,6 @@ public class Fire : MonoBehaviour
|
|||||||
// 如果玩家按住键达到指定时间,停止火焰
|
// 如果玩家按住键达到指定时间,停止火焰
|
||||||
StopFire();
|
StopFire();
|
||||||
isExtinguishing = true; // 防止重复触发灭火
|
isExtinguishing = true; // 防止重复触发灭火
|
||||||
if (XFS.instance.IShavewater)
|
|
||||||
{
|
|
||||||
XFS.instance.water.SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ public class NoFire : MonoBehaviour
|
|||||||
{
|
{
|
||||||
//ÅçÉäµã
|
//ÅçÉäµã
|
||||||
private GameObject MuzzlePos;
|
private GameObject MuzzlePos;
|
||||||
|
|
||||||
|
public bool isuse = false;
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@ -26,10 +28,12 @@ public class NoFire : MonoBehaviour
|
|||||||
public void StartFire()
|
public void StartFire()
|
||||||
{
|
{
|
||||||
MuzzlePos.SetActive(true);
|
MuzzlePos.SetActive(true);
|
||||||
|
isuse=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopFire()
|
public void StopFire()
|
||||||
{
|
{
|
||||||
MuzzlePos.SetActive(false);
|
MuzzlePos.SetActive(false);
|
||||||
|
isuse=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
public class XFS : MonoBehaviour
|
public class XFS : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static XFS instance;
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
public Button ConnectGun;
|
public Button ConnectGun;
|
||||||
public Button ConnectFa;
|
public Button ConnectFa;
|
||||||
@ -22,7 +22,7 @@ public class XFS : MonoBehaviour
|
|||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
ShuiguanGameObject.SetActive(false);
|
ShuiguanGameObject.SetActive(false);
|
||||||
instance =this;
|
UseSkill.Xfs = this;
|
||||||
ConnectGun.onClick.AddListener((() =>
|
ConnectGun.onClick.AddListener((() =>
|
||||||
{
|
{
|
||||||
PLayerLook();
|
PLayerLook();
|
||||||
@ -62,14 +62,15 @@ public class XFS : MonoBehaviour
|
|||||||
|
|
||||||
public void openFa()
|
public void openFa()
|
||||||
{
|
{
|
||||||
water = Instantiate(firewater);
|
UseSkill.Initgun();
|
||||||
|
water = Instantiate(firewater);
|
||||||
water.transform.SetParent(Gun.transform);
|
water.transform.SetParent(Gun.transform);
|
||||||
water.transform.localPosition = new Vector3(0, 0, 0);
|
water.transform.localPosition = new Vector3(0, 0, 0);
|
||||||
water.transform.localRotation = new Quaternion(0, 180, 0, 0);
|
water.transform.localRotation = new Quaternion(0, 180, 0, 0);
|
||||||
CharacterControl.enabled = true;
|
CharacterControl.enabled = true;
|
||||||
water.SetActive(false);
|
water.SetActive(false);
|
||||||
IShavewater = true;
|
IShavewater = true;
|
||||||
UseSkill.Initgun();
|
Gun.GetComponent<watergun>().water=water;
|
||||||
CharacterControl.DragTheScreen.enabled = true;
|
CharacterControl.DragTheScreen.enabled = true;
|
||||||
}
|
}
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
20
xiaofang/Assets/Script/watergun.cs
Normal file
20
xiaofang/Assets/Script/watergun.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class watergun : MonoBehaviour
|
||||||
|
{
|
||||||
|
public XFS Xfs;
|
||||||
|
public GameObject water;
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Xfs=this.transform.parent.GetComponent<XFS>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
xiaofang/Assets/Script/watergun.cs.meta
Normal file
11
xiaofang/Assets/Script/watergun.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9ee3f53d86720f249a148ad9823e0198
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user