Advertisement
kadyr

PlayerController

Aug 24th, 2021
1,398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.     public Transform riffleStartPosition; // ñîçäàåì ïåðåìåííóþ êîòîðàÿ îòâå÷àåò çà ñòàðò âûñòðåëà
  8.     public GameObject bullet;
  9.     private float coolDownShoot = 0.1f;
  10.     private float shootTimer = 0f;
  11.     void Update()
  12.     {
  13.         if (Input.GetMouseButton(0) && shootTimer >= coolDownShoot)
  14.         {
  15.             var bul = Instantiate(bullet, riffleStartPosition.position, riffleStartPosition.rotation);
  16.             bul.GetComponent<Bullet>().SetDirection(transform.forward);
  17.             bul.transform.rotation = transform.rotation;
  18.             shootTimer = 0;
  19.         }
  20.         shootTimer += Time.deltaTime;
  21.     }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement