Дополнен 1 неделю назад
код:using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Unity.VisualScripting;
using UnityEngine;
public class shootscript : MonoBehaviour
{
public bool shoottriger;
public Transform Pointer;
public float magasinvalue = 35;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Cursor.visible = false;
shoottriger = Input.GetKeyDown(KeyCode.Mouse0);
if (shoottriger == true)
{
shootprocces();
}
Ray ray = new Ray();
ray.origin = transform.forward;
ray.direction = transform.forward;
Debug.DrawRay(transform.position,transform.forward * 100,Color.blue);
RaycastHit hit;
if (magasinvalue == 0)
{
Respawn();
}
}
public void shootprocces()
{
Ray ray = new Ray();
ray.origin = transform.forward;
ray.direction = transform.forward;
Debug.DrawRay(transform.position,transform.forward * 100,Color.blue);
RaycastHit hit;
if (Physics.Raycast(ray,out hit) && magasinvalue >= 0)
{
magasinvalue -= 1;
Debug.Log("попал");
Debug.Log("патронов: "+ magasinvalue);
hit.collider.gameObject.GetComponent<HPsystem>().hpcheck();
}
else
{
magasinvalue -= 1;
Debug.Log("не удалось =( ");
Debug.Log("патронов: "+ magasinvalue);
}
}
IEnumerator Respawn()
{
yield return new WaitForSeconds(5f);
magasinvalue =35;
}
}
буду благодарен если поможете