Advertisement
Guest User

xDDD

a guest
Apr 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class playerscript : MonoBehaviour {
  7.     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
  8.     public bool im;//gameplay zmienna
  9.     public Vector3 movedir,mp;//wektor odpowiadający za kierunek gracza,vektor pozycji myszki
  10.     public Vector3 rot;//bedzie przydatne przy rotacji obiektu
  11.     public Rigidbody rb;//nie trzeba wyjaśniać
  12.     public GameObject bullet,sp;//gameplay, scroll down
  13.     public Camera c;//nie trzeba wyjaśniać
  14.     public float dps,timer=0.5f;//nie trzeba wyjaśniać,coś w stylu przyśpieszenia, eksperymentalne i nie ma tego w buildzie
  15.     public float h1,v1;//horyzontalna oś i wertykalna
  16.     public int lives = 3;//nie trzeba wyjaśniać
  17.     public GameObject[] parts = new GameObject[2];//nie trzeba wyjaśniać
  18.     // Use this for initialization
  19.     void Start () {
  20.         rb = GetComponent<Rigidbody> ();
  21.     }
  22.    
  23.     // Update is called once per frame
  24.     void Update () {
  25.         if (rb.velocity == Vector3.zero)//eksperymentalne
  26.             timer = 0.5f;
  27.         if (rb.velocity != Vector3.zero && timer <= 1)
  28.             timer += Time.deltaTime;
  29.        
  30.         if(Input.GetButtonDown("ct"))ct = !ct;//amiana kontroli
  31.         v1 = Input.GetAxis ("V2");
  32.         h1 = Input.GetAxis ("H2");//przypisywanie do osi do zmiennych
  33.         dps += Time.deltaTime;//nie trzeba wyjaśniać
  34.         Transform t = transform;//nie trzeba wyjaśniać
  35.         Quaternion q = new Quaternion ();//nie trzeba wyjaśniać
  36.         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
  37.         if (Input.GetButton("Jump")&& dps > 0.15f) {//strzelanie
  38.             GameObject clone = Instantiate(bullet,sp.transform.position,q);
  39.             clone.GetComponent<Rigidbody>().AddForce(transform.forward * 400);
  40.             dps = 0;
  41.         }
  42.         rb.velocity = movedir;
  43.         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
  44.         //t.LookAt (transform.position+ movedir);
  45.         RaycastHit hit;
  46.         Ray ray = c.ScreenPointToRay(Input.mousePosition);
  47.         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
  48.         if (Physics.Raycast (ray, out hit)&& ct&&Vector3.Distance(hit.point,transform.position)>0.1f) {
  49.             t = transform;
  50.             t.LookAt (hit.point);
  51.             q.eulerAngles = new Vector3 (0,t.rotation.eulerAngles.y,0);
  52.             transform.rotation = q;//pierdolenie z rotacją, zależne od modelu jak wcześniej kilka rzeczy
  53.         }
  54.         if (!ct) {
  55.             t = transform;
  56.             Vector3 lookdir = (new Vector3 (Input.GetAxis ("H2"), 0, Input.GetAxis ("V2"))).normalized * 10;
  57.             if(lookdir!= Vector3.zero)t.LookAt (lookdir);
  58.         }//opcja dla pada
  59.         //transform.rotation = q;
  60.     }//reszta w sumie nie jest potrzebana xDDDd
  61.     void Getdmg(){
  62.         if (!im) {
  63.             lives--;
  64.             if (lives > 0)
  65.                 breakone ();
  66.             if (lives == 0) {
  67.                 lives = 3;
  68.                 Application.LoadLevel( SceneManager.GetActiveScene().buildIndex);
  69.             }
  70.             StartCoroutine ("immortal");
  71.         }
  72.         }
  73.     void breakone(){
  74.         if (parts [0].active == true) {
  75.             parts [0].SetActive(false);
  76.         }
  77.         else parts [1].SetActive(false);
  78.     }
  79.     public IEnumerator immortal(){
  80.         im = true;
  81.         gameObject.layer = 9;
  82.         Renderer[] g = GetComponentsInChildren<Renderer> ();
  83.         foreach (Renderer a in g) {
  84.             a.material.color = new Color(a.material.color.r,a.material.color.g,a.material.color.b,0);
  85.         }
  86.         yield return new  WaitForSeconds (1);
  87.         im = false;
  88.         gameObject.layer = 12;
  89.         foreach (Renderer a in g) {
  90.             a.material.color = new Color(a.material.color.r,a.material.color.g,a.material.color.b,1);
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement