_xiaofang/xiaofang/Assets/Script/Character/Skills/UseSkill.cs
2024-12-26 04:17:03 +08:00

164 lines
4.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/*
* 使用技能,需要人物身上有动画控制脚本
*
*/
public class UseSkill : MonoBehaviour
{
//private CharacterAin CharacterAin;
// 玩家手中当前持有的物品
//[HideInInspector]
public GameObject currentItem = null;
public Skill_Pick _skill_Pick;
public Skill_Jump _skill_Jump;
public Skill_watering _skill_Watering;
//Fire fire = new Fire();
public Button WaterButton;
public bool IsWater = false;
// Start is called before the first frame update
void Start()
{
_skill_Pick = transform.GetComponent<Skill_Pick>();
_skill_Jump = transform.GetComponent<Skill_Jump>();
_skill_Watering = transform.GetComponent<Skill_watering>();
WaterButton.onClick.AddListener(Skill_Watering);
//Debug.LogError(_skill_Pick.Pick());
}
// Update is called once per frame
void Update()
{
//Skill_Watering();
//Skill_Pick();
if (currentItem != null)
{
if(currentItem.gameObject.name=="gun")
{
float dis= Vector3.Distance(GameObject.Find("player").transform.position, XFS.instance.transform.position);
if (dis >= 30f)
{
Drop();
}
}
}
}
//连接水管
public void Initgun()
{
if (currentItem != null)
{
currentItem = _skill_Pick.Drop(currentItem);
currentItem = null;
}
currentItem = _skill_Pick.Pick();
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);
}
}
public void Pick()
{
if (currentItem != null)
{
currentItem = _skill_Pick.Drop(currentItem);
currentItem = null;
}
currentItem = _skill_Pick.Pick();
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);
}
}
public void Drop()
{
currentItem = _skill_Pick.Drop(currentItem);
}
//拾取
void Skill_Pick()
{
//Debug.LogError(skill_Pick.Pick());
if (currentItem != null) { currentItem = _skill_Pick.Drop(currentItem); currentItem=null;
}
currentItem = _skill_Pick.Pick();
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 (Input.GetKeyDown(KeyCode.Q))
{
currentItem = _skill_Pick.Drop(currentItem);
}
}
//洒水
void Skill_Watering()
{
if (currentItem == null)
{
return;
}
Debug.Log(00000000000000000);
IsWater=true;
_skill_Watering.StartWatering(currentItem);
//if (Input.GetMouseButtonUp(0) &&! EventSystem.current.IsPointerOverGameObject())
//{
// IsWater = false;
// _skill_Watering.StopWatering(currentItem);
// if (currentItem.gameObject.name == "gun")
// {
// if (XFS.instance.IShavewater)
// {
// XFS.instance.water.SetActive(false);
// }
// //currentItem.transform.rotation = new Quaternion(0, 180f,0, 0);
// }
//}
}
public void FireOUt()
{IsWater=false;
if (currentItem != null)
{
_skill_Watering.StopWatering(currentItem);
}
_skill_Watering.StopWateringAnim();
}
}