Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float speed = 8f;
- float rotSpeed = 140f;
- float rot = 0f;
- float Gravity = 6f;
- float distance = 1f;
- public static float weapon;
- public static float damage = 10f;
- public static float health;
- public static float maxHealth = 100f;
- bool isAlive = true;
- public static bool isPaused = false;
- public Collider swordCollider;
- public Collider bodyCollider;
- private int allSlots;
- private int enabledSlots;
- private bool inventoryOn;
- public GameObject inventory;
- Vector3 moveDir;
- CharacterController Controller;
- Animator anim;
- void Start()
- {
- Controller = GetComponent<CharacterController> ();
- anim = GetComponent<Animator> ();
- Cursor.visible = false;
- health = maxHealth;
- swordCollider.enabled = false;
- }
- void Update()
- {
- Move();
- Look();
- StartCoroutine(AttackRoutine());
- CheckIfInvOn();
- if (health <= 0) { Destroy(this.gameObject); }
- }
- void Move()
- {
- if (Input.GetKey(KeyCode.W))
- {
- if (anim.GetBool("Attacking") == true) { return; }
- else if (anim.GetBool("Attacking") == false)
- {
- anim.SetBool("Walking", true);
- anim.SetInteger("Condition", 1);
- moveDir = new Vector3(0f, 0f, Input.GetAxis("Vertical") * speed);
- moveDir = transform.TransformDirection(Vector3.forward) * speed;
- moveDir.y -= Gravity;
- Controller.Move(moveDir * Time.deltaTime);
- }
- }
- if (Input.GetKeyUp(KeyCode.W))
- {
- anim.SetBool("Walking", false);
- anim.SetInteger("Condition", 0);
- }
- }
- void Look()
- {
- RaycastHit hit;
- Ray mousePos = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(mousePos, out hit))
- {
- transform.LookAt(new Vector3(hit.point.x, transform.position.y, hit.point.z));
- }
- }
- IEnumerator AttackRoutine()
- {
- if (Input.GetKey(KeyCode.Mouse0))
- {
- anim.SetBool("Attacking", true);
- anim.SetInteger("Condition", 2);
- yield return new WaitForSeconds(0.4f);
- swordCollider.enabled = !swordCollider.enabled;
- yield return new WaitForSeconds(0.35f);
- swordCollider.enabled = !swordCollider.enabled;
- anim.SetBool("Attacking", false);
- anim.SetInteger("Condition", 0);
- }
- }
- private void OnTriggerEnter(Collider body)
- {
- if(body.CompareTag("Enemy")) { health -= 10f; }
- Debug.Log(health);
- }
- void CheckIfInvOn()
- {
- if (Input.GetKeyDown(KeyCode.E)) { inventoryOn = !inventoryOn; }
- if(inventoryOn == true)
- {
- inventory.SetActive(true);
- Time.timeScale = 0f;
- Cursor.visible = true;
- }
- else
- {
- inventory.SetActive(false);
- Cursor.visible = false;
- Time.timeScale = 1f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement