Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class playerscript : MonoBehaviour {
- public static bool ct;//zmiana ustawień starowania, DefaultExecutionOrder - ParticleSystemCustomData, pocisk kliknięciu klawisza zmienia się sterowanie rotacji gracza, albo myszka albo gałka na padzie
- public bool im;//gameplay zmienna
- public Vector3 movedir,mp;//wektor odpowiadający za kierunek gracza,vektor pozycji myszki
- public Vector3 rot;//bedzie przydatne przy rotacji obiektu
- public Rigidbody rb;//nie trzeba wyjaśniać
- public GameObject bullet,sp;//gameplay, scroll down
- public Camera c;//nie trzeba wyjaśniać
- public float dps,timer=0.5f;//nie trzeba wyjaśniać,coś w stylu przyśpieszenia, eksperymentalne i nie ma tego w buildzie
- public float h1,v1;//horyzontalna oś i wertykalna
- public int lives = 3;//nie trzeba wyjaśniać
- public GameObject[] parts = new GameObject[2];//nie trzeba wyjaśniać
- // Use this for initialization
- void Start () {
- rb = GetComponent<Rigidbody> ();
- }
- // Update is called once per frame
- void Update () {
- if (rb.velocity == Vector3.zero)//eksperymentalne
- timer = 0.5f;
- if (rb.velocity != Vector3.zero && timer <= 1)
- timer += Time.deltaTime;
- if(Input.GetButtonDown("ct"))ct = !ct;//amiana kontroli
- v1 = Input.GetAxis ("V2");
- h1 = Input.GetAxis ("H2");//przypisywanie do osi do zmiennych
- dps += Time.deltaTime;//nie trzeba wyjaśniać
- Transform t = transform;//nie trzeba wyjaśniać
- Quaternion q = new Quaternion ();//nie trzeba wyjaśniać
- q.eulerAngles = new Vector3 (transform.rotation.eulerAngles.x+90,transform.rotation.eulerAngles.y-90,transform.rotation.eulerAngles.z);//przydaje się póżniej, +-90 zależy od początkowej rotacji modelu
- if (Input.GetButton("Jump")&& dps > 0.15f) {//strzelanie
- GameObject clone = Instantiate(bullet,sp.transform.position,q);
- clone.GetComponent<Rigidbody>().AddForce(transform.forward * 400);
- dps = 0;
- }
- rb.velocity = movedir;
- movedir = (new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"))).normalized*1.5f*timer;//no troche dziwne że robi się to dopiero w następnej klatce no ale co zrobić xD
- //t.LookAt (transform.position+ movedir);
- RaycastHit hit;
- Ray ray = c.ScreenPointToRay(Input.mousePosition);
- Debug.DrawRay (ray.origin, ray.direction*10);//chyba wiesz o co w tym chodzi, w naszej gierce polecam prowadzenie takiego raycasta w oddzielnej warstwie tylko do rotacji gracza
- if (Physics.Raycast (ray, out hit)&& ct&&Vector3.Distance(hit.point,transform.position)>0.1f) {
- t = transform;
- t.LookAt (hit.point);
- q.eulerAngles = new Vector3 (0,t.rotation.eulerAngles.y,0);
- transform.rotation = q;//pierdolenie z rotacją, zależne od modelu jak wcześniej kilka rzeczy
- }
- if (!ct) {
- t = transform;
- Vector3 lookdir = (new Vector3 (Input.GetAxis ("H2"), 0, Input.GetAxis ("V2"))).normalized * 10;
- if(lookdir!= Vector3.zero)t.LookAt (lookdir);
- }//opcja dla pada
- //transform.rotation = q;
- }//reszta w sumie nie jest potrzebana xDDDd
- void Getdmg(){
- if (!im) {
- lives--;
- if (lives > 0)
- breakone ();
- if (lives == 0) {
- lives = 3;
- Application.LoadLevel( SceneManager.GetActiveScene().buildIndex);
- }
- StartCoroutine ("immortal");
- }
- }
- void breakone(){
- if (parts [0].active == true) {
- parts [0].SetActive(false);
- }
- else parts [1].SetActive(false);
- }
- public IEnumerator immortal(){
- im = true;
- gameObject.layer = 9;
- Renderer[] g = GetComponentsInChildren<Renderer> ();
- foreach (Renderer a in g) {
- a.material.color = new Color(a.material.color.r,a.material.color.g,a.material.color.b,0);
- }
- yield return new WaitForSeconds (1);
- im = false;
- gameObject.layer = 12;
- foreach (Renderer a in g) {
- a.material.color = new Color(a.material.color.r,a.material.color.g,a.material.color.b,1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement