Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour {
- public CharacterController2D controller;
- public Animator animator;
- public GameObject jumpfx;
- public GameObject landfx;
- public GameObject Camera;
- public GameObject pointsItem;
- public GameObject pointsEmitter;
- private int itemCount = -10;
- private int targetCount;
- public float runSpeed = 40f;
- public float positive_threshold;
- public float negative_threshold;
- float horizontalMove = 0f;
- bool jump = false;
- bool crouch = false;
- public AudioClip jumpClip;
- public AudioClip powerUpClip;
- public AudioClip normalFireClip;
- public AudioClip pointsUpClip;
- public GameObject crownrun;
- public GameObject crownidle;
- public GameObject crownEmitter;
- public TimeManager timeManager;
- private bool sprinting;
- private bool idling;
- void Start () {
- AudioSource audio = GetComponent<AudioSource>();
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown("c"))
- {
- SumScore.ClearHighScore();
- }
- AudioSource audio = GetComponent<AudioSource>();
- horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
- animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
- if (Input.GetButtonDown("Fire1") && GetComponent<CharacterController2D>().m_Grounded == true) //(transform.position.y < positive_threshold) && (transform.position.y > negative_threshold))
- {
- jump = true;
- animator.SetBool("IsJumping", jump);
- Instantiate(jumpfx, transform.position, Quaternion.identity);
- audio.clip = jumpClip;
- audio.Play();
- }
- }
- public void OnLanding()
- {
- animator.SetBool("IsJumping", false);
- Instantiate(landfx, transform.position, Quaternion.identity);
- }
- void FixedUpdate ()
- {
- // Move our character
- controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
- jump = false;
- }
- void OnCollisionEnter2D(Collision2D col)
- {
- if(col.gameObject.tag == "om")
- {
- SumScore.Add(10);
- StartCoroutine(changeFireRate());
- }
- if(col.gameObject.tag == "ministar")
- {
- SumScore.Add(200);
- Instantiate(pointsItem, pointsEmitter.transform.position, Quaternion.identity);
- StartCoroutine(startSprint());
- }
- if(col.gameObject.tag == "item")
- {
- itemCount = itemCount + 1;
- DisplayItemReward ();
- }
- }
- void DisplayItemReward()
- {
- //Check if we've collected all 10 pickups. If we have...
- if (itemCount >= targetCount)
- {
- AudioSource audio = GetComponent<AudioSource>();
- Instantiate(pointsItem, pointsEmitter.transform.position, Quaternion.identity);
- targetCount += 10;
- SumScore.Add(200);
- audio.clip = pointsUpClip;
- audio.Play();
- }
- }
- IEnumerator changeFireRate()
- {
- AudioSource audio = GetComponent<AudioSource>();
- shoot.fireRate = 15f;
- GameObject.FindGameObjectWithTag("boss").GetComponent<skullAttack>().fireRate = 0.25f;
- audio.clip = powerUpClip;
- audio.Play();
- yield return new WaitForSeconds(10);
- audio.clip = normalFireClip;
- audio.Play();
- shoot.fireRate = 5f;
- GameObject.FindGameObjectWithTag("boss").GetComponent<skullAttack>().fireRate = 1f;
- }
- IEnumerator startSprint()
- {
- if (animator.GetCurrentAnimatorStateInfo(0).IsName("run_run"))
- {
- crownidle.GetComponent<SpriteRenderer>().enabled = false;
- crownidle.GetComponent<Animator>().enabled = false;
- crownrun.GetComponent<SpriteRenderer>().enabled = true;
- crownrun.GetComponent<Animator>().enabled = true;
- animator.Play("run_run", 0, 0f);
- GetComponent<PlayerMovement>().runSpeed = 70f;
- GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().ghosts = 10;
- GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().updateInterval = 0.09f;
- }
- else if (animator.GetCurrentAnimatorStateInfo(0).IsName("idle_idle"))
- {
- crownrun.GetComponent<SpriteRenderer>().enabled = false;
- crownrun.GetComponent<Animator>().enabled = false;
- crownidle.GetComponent<SpriteRenderer>().enabled = true;
- crownidle.GetComponent<Animator>().enabled = true;
- animator.Play("idle_idle", 0, 0f);
- GetComponent<PlayerMovement>().runSpeed = 70f;
- GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().ghosts = 10;
- GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().updateInterval = 0.09f;
- }
- yield return new WaitForSeconds(5f);
- crownrun.GetComponent<SpriteRenderer>().enabled = false;
- crownrun.GetComponent<Animator>().enabled = false;
- animator.Play("run_run", 0, 0f);
- GetComponent<PlayerMovement>().runSpeed = 50f;
- GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().ghosts = 5;
- GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().updateInterval = 0.03f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement