Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using DefaultNamespace;
- using UnityEngine;
- public class Switch : MonoBehaviour
- {
- public GameObject riffle;
- public GameObject shotgun;
- public GameObject pistol;
- private Gun currentGun;
- int level = 1;
- public enum Weapon
- {
- Pistol,
- Shotgun,
- Riffle
- }
- void Start()
- {
- switch (level)
- {
- case 1:
- ChooseWeapon(Weapon.Pistol);
- break;
- case 2:
- ChooseWeapon(Weapon.Shotgun);
- break;
- case 3:
- ChooseWeapon(Weapon.Riffle);
- break;
- default:
- print("Для этого уровня не подготовлено оружие");
- break;
- }
- }
- private void Update()
- {
- if(Input.GetMouseButton(0))
- currentGun.Shoot();
- if (Input.GetKeyDown(KeyCode.Alpha1))
- ChooseWeapon(Weapon.Pistol);
- if (Input.GetKeyDown(KeyCode.Alpha2))
- ChooseWeapon(Weapon.Shotgun);
- if (Input.GetKeyDown(KeyCode.Alpha3))
- ChooseWeapon(Weapon.Riffle);
- }
- private void ChooseWeapon(Weapon weaponName)
- {
- switch (weaponName)
- {
- case Weapon.Pistol:
- riffle.SetActive(false);
- shotgun.SetActive(false);
- pistol.SetActive(true);
- currentGun = GetComponentInChildren<Pistol>();
- break;
- case Weapon.Shotgun:
- riffle.SetActive(false);
- shotgun.SetActive(true);
- pistol.SetActive(false);
- currentGun = GetComponentInChildren<Shotgun>();
- break;
- case Weapon.Riffle:
- riffle.SetActive(true);
- shotgun.SetActive(false);
- pistol.SetActive(false);
- currentGun = GetComponentInChildren<Riffle>();
- break;
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using Photon.Realtime;
- using UnityEngine;
- public class Pistol : Gun
- {
- private Quaternion pc;
- void Start()
- {
- damage = 20;
- cooldown = 0.5f;
- speed = 25f;
- auto = false;
- pc = GetComponentInParent<PlayerController>().transform.rotation;
- }
- protected override void OnShoot()
- {
- GameObject bol = Instantiate(bullet, riffleStart.transform.position,pc);
- bol.GetComponent<Bullet>().setDirection(GetComponentInParent<PlayerController>().transform.forward);
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Gun : MonoBehaviour
- {
- [SerializeField]
- protected Transform riffleStart;
- [SerializeField]
- protected GameObject bullet;
- protected int damage = 0;
- protected float speed = 20f;
- protected float cooldown = 0;
- protected bool auto = false;
- private float timer = 0;
- public void Shoot()
- {
- if (Input.GetMouseButtonDown(0) || auto)
- {
- if (timer > cooldown)
- {
- OnShoot();
- timer = 0;
- }
- }
- }
- protected virtual void OnShoot(){ }
- void Start()
- {
- timer = cooldown;
- }
- // Update is called once per frame
- void Update()
- {
- timer += Time.deltaTime;
- }
- }
- using ExitGames.Client.Photon.StructWrapping;
- using UnityEngine;
- namespace DefaultNamespace
- {
- public class Shotgun:Gun
- {
- void Start()
- {
- damage = 5;
- auto = false;
- cooldown = 0;
- speed = 0;
- }
- protected override void OnShoot()
- {
- for (int i = 0; i < 15; i++)
- {
- GameObject bul = Instantiate(bullet);
- bul.transform.position = riffleStart.transform.position;
- float x = Random.Range(-10, 10);
- float y = Random.Range(-15, 15);
- bul.transform.rotation = transform.rotation;
- bul.GetComponent<Bullet>().setDirection(transform.forward+new Vector3(x/100,y/100,0));
- }
- }
- }
- }
- using UnityEngine;
- using UnityEngine.UI;
- public class PlayerController : MonoBehaviour
- {
- [SerializeField]
- Text HpText;
- int health;
- [SerializeField]
- GameObject gameOver;
- [SerializeField]
- GameObject pauseUI;
- bool pause;
- public void ChangeHealth(int count)
- {
- health = health + count;
- if (health <= 0)
- {
- gameOver.SetActive(true);
- GetComponent<PlayerLook>().enabled = false;
- Cursor.lockState = CursorLockMode.None;
- }
- // HpText.text = health.ToString();
- }
- public int GetHealth()
- {
- return health;
- }
- // Start is called before the first frame update
- void Start()
- {
- ChangeHealth(100);
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- if (pause == true)
- {
- pause = false;
- GetComponent<PlayerLook>().enabled = true;
- GetComponent<PlayerMove>().enabled = true;
- Cursor.lockState = CursorLockMode.Locked;
- pauseUI.SetActive(false);
- }
- else
- {
- pause = true;
- GetComponent<PlayerLook>().enabled = false;
- GetComponent<PlayerMove>().enabled = false;
- Cursor.lockState = CursorLockMode.None;
- pauseUI.SetActive(true);
- }
- }
- }
- private void OnTriggerEnter(Collider collider)
- {
- if (collider.tag == "Health")
- {
- print("health");
- Destroy(collider.gameObject);
- ChangeHealth(50);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement