Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Shoot : MonoBehaviour
{
public Transform shootPoint;
public GameObject Bullet;
public float BulletSpeed;
public Animator anim;
private Vector2 direction;
public float fireRate;
private float ReadyForNextShot;
public GameManager gm;
public Player player;
public bool giga;
public GameObject Bullet1;
public AudioSource source;
public AudioClip shoot;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
direction = mousePos - (Vector2) shootPoint.position;
FaceMouse();
if (!gm.dialogue && !player.hasTransformed)
{
if (Input.GetMouseButton(0))
{
if (Time.time > ReadyForNextShot)
{
ReadyForNextShot = Time.time + 1 / fireRate;
Shooting();
}
}
}
}
void FaceMouse()
{
shootPoint.transform.right = direction;
}
public void Shooting()
{
if (giga)
{
GameObject bulletins = Instantiate(Bullet1, shootPoint.position, shootPoint.rotation);
bulletins.GetComponent().AddForce(bulletins.transform.right * BulletSpeed);
}
else if (!giga)
{
GameObject bulletins = Instantiate(Bullet, shootPoint.position, shootPoint.rotation);
bulletins.GetComponent().AddForce(bulletins.transform.right * BulletSpeed);
}
source.clip = shoot;
print(source.isPlaying);
anim.SetTrigger("shoot");
}
}