Facebook
From Platon Games , 5 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 240
  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;
  8.         public bool im;
  9.         public Vector3 movedir,mp;
  10.         public Vector3 rot;
  11.         public Rigidbody rb;
  12.         public GameObject bullet,sp;
  13.         public Camera c;
  14.         public float dps,timer=0.5f;
  15.         public float h1,v1;
  16.         public int lives = 3;
  17.         public GameObject[] parts = new GameObject[2];
  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)
  26.                         timer = 0.5f;
  27.                 if (rb.velocity != Vector3.zero && timer <= 1)
  28.                         timer += Time.deltaTime;
  29.                 if(Input.GetButtonDown("ct"))ct = !ct;
  30.                 v1 = Input.GetAxis ("V2");
  31.                 h1 = Input.GetAxis ("H2");
  32.                 dps += Time.deltaTime;
  33.                 Transform t = transform;
  34.                 Quaternion q = new Quaternion ();
  35.                 q.eulerAngles = new Vector3 (transform.rotation.eulerAngles.x+90,transform.rotation.eulerAngles.y-90,transform.rotation.eulerAngles.z);
  36.                 if (Input.GetButton("Jump")&& dps > 0.15f) {
  37.                         GameObject clone = Instantiate(bullet,sp.transform.position,q);
  38.                         clone.GetComponent<Rigidbody>().AddForce(transform.forward * 400);
  39.                         dps = 0;
  40.                 }
  41.                 rb.velocity = movedir;
  42.                 movedir = (new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"))).normalized*1.5f*timer;
  43.                 //t.LookAt (transform.position+ movedir);
  44.                 RaycastHit hit;
  45.                 Ray ray = c.ScreenPointToRay(Input.mousePosition);
  46.                 Debug.DrawRay (ray.origin, ray.direction*10);
  47.                 if (Physics.Raycast (ray, out hit)&& ct&&Vector3.Distance(hit.point,transform.position)>0.1f) {
  48.                         t = transform;
  49.                         t.LookAt (hit.point);
  50.                         q.eulerAngles = new Vector3 (0,t.rotation.eulerAngles.y,0);
  51.                         transform.rotation = q;
  52.                 }
  53.                 if (!ct) {
  54.                         t = transform;
  55.                         Vector3 lookdir = (new Vector3 (Input.GetAxis ("H2"), 0, Input.GetAxis ("V2"))).normalized * 10;
  56.                         if(lookdir!= Vector3.zero)t.LookAt (lookdir);
  57.                 }
  58.                 //transform.rotation = q;
  59.         }
  60.         void Getdmg(){
  61.                 if (!im) {
  62.                         lives--;
  63.                         if (lives > 0)
  64.                                 breakone ();
  65.                         if (lives == 0) {
  66.                                 lives = 3;
  67.                                 Application.LoadLevel( SceneManager.GetActiveScene().buildIndex);
  68.                         }
  69.                         StartCoroutine ("immortal");
  70.                 }
  71.                 }
  72.         void breakone(){
  73.                 if (parts [0].active == true) {
  74.                         parts [0].SetActive(false);
  75.                 }
  76.                 else parts [1].SetActive(false);
  77.         }
  78.         public IEnumerator immortal(){
  79.                 im = true;
  80.                 gameObject.layer = 9;
  81.                 Renderer[] g = GetComponentsInChildren<Renderer> ();
  82.                 foreach (Renderer a in g) {
  83.                         a.material.color = new Color(a.material.color.r,a.material.color.g,a.material.color.b,0);
  84.                 }
  85.                 yield return new  WaitForSeconds (1);
  86.                 im = false;
  87.                 gameObject.layer = 12;
  88.                 foreach (Renderer a in g) {
  89.                         a.material.color = new Color(a.material.color.r,a.material.color.g,a.material.color.b,1);
  90.                 }
  91.         }
  92. }
  93.