Загрузка данных


using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.Timeline;

public class firstSpells : MonoBehaviour
{
    [Header("Abilitys")]
    public GameObject fireShot;
    public GameObject IceShot;
    public GameObject ShotSpawn;

    [Header("Abilitys Settings")]
    public float FireDamage = 10f;
    public float Firespeed = 300f;
    public float FireManaCost = 20f;
    public float IceDamage = 15f;
    public float Icespeed = 100f;
    public float IceManaCost = 10f;
    public float maxDistance = 100f;
    public float refiilShoot = 1f;
    public float nextRefiil;

    [Header("Links")]
    public pickUp pickUp;
    public CharacterStats stats;
    public Camera PlayerCamera;
    public LayerMask iqnoreLayer;
    public GameObject[] staffLights;
    //public SpellsTake spellsTake;

    [ColorUsage(true, true)] public Color firecolor = Color.red;
    [ColorUsage(true, true)] public Color Icecolor = Color.blue;
    private bool fireSelected = true;
    
    void Start()
    {
        ColorUpdate();
        nextRefiil = Time.time + refiilShoot;
    }
    
   
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q)) fireSelected = !fireSelected;
        ColorUpdate();

        if (Input.GetKeyDown(KeyCode.Mouse0) && pickUp.curriedObject != null && Time.time >= nextRefiil)
        {
            if (pickUp.curriedObject.CompareTag("Staff"))
            {
                TryCastSpell();
            }
        }
    }
    void TryCastSpell()
    {
        float manaCost = fireSelected ? FireManaCost : IceManaCost;
        float currentSpeed = fireSelected ? Firespeed : Icespeed;
        float currentDamage = fireSelected ? FireDamage : IceDamage;
        GameObject PrefabSelected = fireSelected ? fireShot : IceShot;
        if ( stats.UseMana(manaCost))
        {
            Shoot(PrefabSelected,currentSpeed,currentDamage);
        }
        else
        {
            Debug.Log("No mana");
        }
    }
    void ColorUpdate()
    {
        if (pickUp.curriedObject != null && pickUp.curriedObject.CompareTag("Staff"))
       { 
        Color activeColor = fireSelected ? firecolor : Icecolor;
        foreach (GameObject lightobj in staffLights )
         {
            if (lightobj != null && pickUp.curriedObject != null)
            {
                Light lightComp = lightobj.GetComponent<Light>();
                if (lightComp != null)
                {
                    lightComp.color = activeColor;
                }
            }
         }
       }
    }
    void Shoot(GameObject PrefabSelected, float currentSpeed, float spellDamage)
    {

        Ray ray = PlayerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));//����  ������� 
        RaycastHit hit;
        Vector3 targetPoint;
        if (Physics.Raycast(ray, out hit, 100f, ~iqnoreLayer, QueryTriggerInteraction.Ignore))// ������ � ����� � ����, ���� ��� �  100 ���� ������
            targetPoint = hit.point;
        else
            targetPoint = ray.GetPoint(100f);
        Vector3 spawnPos = PlayerCamera.transform.position + PlayerCamera.transform.forward * 1.5f;
        Vector3 direction = (targetPoint - spawnPos).normalized;

        // Если цель слишком близко (почти совпадает со spawnPos) — используем forward камеры
        if ((targetPoint - spawnPos).sqrMagnitude < 0.01f)
            direction = PlayerCamera.transform.forward;
        //Debug.Log($"Camera pos: {PlayerCamera.transform.position}, Y: {PlayerCamera.transform.position.y}")fd;
        //Debug.Log($"CameraWorldY: {PlayerCamera.transform.position.y}, CameraLocalY: {PlayerCamera.transform.localPosition.y}");
        Debug.Log("Стреляем! Спавн: " + spawnPos + " | Прицел: " + targetPoint + " | Вектор: " + direction);
        Debug.DrawLine(spawnPos, targetPoint, Color.red, 5f);



        GameObject newSpells = Instantiate(PrefabSelected, spawnPos, Quaternion.LookRotation(direction));
        Rigidbody rb = newSpells.GetComponent<Rigidbody>();
        
        

        if (rb != null)
        {
            rb.useGravity = false; 
            rb.linearVelocity = direction * currentSpeed;
        }
        SpellsTake spellScript = newSpells.GetComponent<SpellsTake>();
        if (spellScript != null)
        {
            spellScript.damage = spellDamage;
        }
        else
        {
            Debug.LogError("Нет скрипта на пуле");
        }
            Debug.DrawLine(spawnPos, targetPoint, Color.cyan, 1f);
        Destroy(newSpells, 2f);
        nextRefiil = Time.time + refiilShoot;
    }
}