Advertisement
kadyr

Untitled

Sep 4th, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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. public GameObject grenade;
  10. private float coolDownShoot = 0.1f;
  11. private float shootTimer = 0f;
  12. void Update()
  13. {
  14. if (Input.GetMouseButton(0) && shootTimer >= coolDownShoot)
  15. {
  16. var bul = Instantiate(bullet, riffleStartPosition.position, riffleStartPosition.rotation);
  17. bul.GetComponent<Bullet>().SetDirection(transform.forward);
  18. bul.transform.rotation = transform.rotation;
  19. shootTimer = 0;
  20. }
  21.  
  22. if (Input.GetKeyDown(KeyCode.E))
  23. {
  24. var t = Instantiate(grenade, transform.position+transform.forward*2f+new Vector3(0,2,0), Quaternion.identity);
  25. t.GetComponent<Rigidbody>().AddForce(transform.forward*20f,ForceMode.Impulse);
  26. }
  27. shootTimer += Time.deltaTime;
  28. }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement