using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class playerscript : MonoBehaviour { public static bool ct; public bool im; public Vector3 movedir,mp; public Vector3 rot; public Rigidbody rb; public GameObject bullet,sp; public Camera c; public float dps,timer=0.5f; public float h1,v1; public int lives = 3; public GameObject[] parts = new GameObject[2]; // Use this for initialization void Start () { rb = GetComponent (); } // Update is called once per frame void Update () { if (rb.velocity == Vector3.zero) timer = 0.5f; if (rb.velocity != Vector3.zero && timer <= 1) timer += Time.deltaTime; if(Input.GetButtonDown("ct"))ct = !ct; v1 = Input.GetAxis ("V2"); h1 = Input.GetAxis ("H2"); dps += Time.deltaTime; Transform t = transform; Quaternion q = new Quaternion (); q.eulerAngles = new Vector3 (transform.rotation.eulerAngles.x+90,transform.rotation.eulerAngles.y-90,transform.rotation.eulerAngles.z); if (Input.GetButton("Jump")&& dps > 0.15f) { GameObject clone = Instantiate(bullet,sp.transform.position,q); clone.GetComponent().AddForce(transform.forward * 400); dps = 0; } rb.velocity = movedir; movedir = (new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"))).normalized*1.5f*timer; //t.LookAt (transform.position+ movedir); RaycastHit hit; Ray ray = c.ScreenPointToRay(Input.mousePosition); Debug.DrawRay (ray.origin, ray.direction*10); 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; } if (!ct) { t = transform; Vector3 lookdir = (new Vector3 (Input.GetAxis ("H2"), 0, Input.GetAxis ("V2"))).normalized * 10; if(lookdir!= Vector3.zero)t.LookAt (lookdir); } //transform.rotation = q; } 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 (); 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); } } }