Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- public Transform riffleStartPosition; // ������� ���������� ������� �������� �� ����� ��������
- public GameObject bullet;
- public GameObject grenade;
- private float coolDownShoot = 0.1f;
- private float shootTimer = 0f;
- void Update()
- {
- if (Input.GetMouseButton(0) && shootTimer >= coolDownShoot)
- {
- var bul = Instantiate(bullet, riffleStartPosition.position, riffleStartPosition.rotation);
- bul.GetComponent<Bullet>().SetDirection(transform.forward);
- bul.transform.rotation = transform.rotation;
- shootTimer = 0;
- }
- if (Input.GetKeyDown(KeyCode.E))
- {
- var t = Instantiate(grenade, transform.position+transform.forward*2f+new Vector3(0,2,0), Quaternion.identity);
- t.GetComponent<Rigidbody>().AddForce(transform.forward*20f,ForceMode.Impulse);
- }
- shootTimer += Time.deltaTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement