Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMovement : MonoBehaviour {
  6.  
  7.     public CharacterController2D controller;
  8.     public Animator animator;
  9.     public GameObject jumpfx;
  10.     public GameObject landfx;
  11.     public GameObject Camera;
  12.     public GameObject pointsItem;
  13.     public GameObject pointsEmitter;
  14.  
  15.     private int itemCount = -10;
  16.     private int targetCount;
  17.  
  18.     public float runSpeed = 40f;
  19.     public float positive_threshold;
  20.     public float negative_threshold;
  21.  
  22.     float horizontalMove = 0f;
  23.     bool jump = false;
  24.     bool crouch = false;
  25.  
  26.     public AudioClip jumpClip;
  27.     public AudioClip powerUpClip;
  28.     public AudioClip normalFireClip;
  29.     public AudioClip pointsUpClip;
  30.  
  31.     public GameObject crownrun;
  32.     public GameObject crownidle;
  33.     public GameObject crownEmitter;
  34.  
  35.     public TimeManager timeManager;
  36.  
  37.     private bool sprinting;
  38.     private bool idling;
  39.  
  40.     void Start () {
  41.         AudioSource audio = GetComponent<AudioSource>();
  42.     }
  43.  
  44.     // Update is called once per frame
  45.     void Update () {
  46.  
  47.         if (Input.GetKeyDown("c"))
  48.         {
  49.             SumScore.ClearHighScore();
  50.         }
  51.  
  52.         AudioSource audio = GetComponent<AudioSource>();
  53.  
  54.         horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
  55.  
  56.         animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
  57.  
  58.         if (Input.GetButtonDown("Fire1") && GetComponent<CharacterController2D>().m_Grounded == true) //(transform.position.y < positive_threshold) && (transform.position.y > negative_threshold))
  59.         {
  60.             jump = true;
  61.             animator.SetBool("IsJumping", jump);
  62.             Instantiate(jumpfx, transform.position, Quaternion.identity);
  63.             audio.clip = jumpClip;
  64.             audio.Play();
  65.         }                              
  66.     }
  67.  
  68.     public void OnLanding()
  69.     {
  70.         animator.SetBool("IsJumping", false);
  71.         Instantiate(landfx, transform.position, Quaternion.identity);
  72.     }
  73.  
  74.     void FixedUpdate ()
  75.     {
  76.         // Move our character
  77.         controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
  78.         jump = false;
  79.     }
  80.  
  81.     void OnCollisionEnter2D(Collision2D col)
  82.     {
  83.         if(col.gameObject.tag == "om")
  84.         {
  85.             SumScore.Add(10);
  86.             StartCoroutine(changeFireRate());
  87.         }
  88.  
  89.         if(col.gameObject.tag == "ministar")
  90.         {
  91.             SumScore.Add(200);
  92.             Instantiate(pointsItem, pointsEmitter.transform.position, Quaternion.identity);
  93.             StartCoroutine(startSprint()); 
  94.         }      
  95.  
  96.         if(col.gameObject.tag == "item")
  97.         {
  98.             itemCount = itemCount + 1;
  99.             DisplayItemReward ();
  100.         }
  101.     }
  102.  
  103.     void DisplayItemReward()
  104.     {
  105.         //Check if we've collected all 10 pickups. If we have...
  106.         if (itemCount >= targetCount)
  107.         {
  108.             AudioSource audio = GetComponent<AudioSource>();
  109.  
  110.             Instantiate(pointsItem, pointsEmitter.transform.position, Quaternion.identity);
  111.             targetCount += 10;
  112.             SumScore.Add(200);
  113.            
  114.             audio.clip = pointsUpClip;
  115.             audio.Play();          
  116.         }  
  117.     }  
  118.  
  119.     IEnumerator changeFireRate()
  120.     {
  121.         AudioSource audio = GetComponent<AudioSource>();
  122.  
  123.         shoot.fireRate = 15f;
  124.         GameObject.FindGameObjectWithTag("boss").GetComponent<skullAttack>().fireRate = 0.25f;
  125.  
  126.         audio.clip = powerUpClip;
  127.         audio.Play();
  128.  
  129.         yield return new WaitForSeconds(10);
  130.  
  131.         audio.clip = normalFireClip;
  132.         audio.Play();      
  133.         shoot.fireRate = 5f;
  134.         GameObject.FindGameObjectWithTag("boss").GetComponent<skullAttack>().fireRate = 1f;
  135.     }
  136.  
  137.     IEnumerator startSprint()
  138.     {
  139.         if (animator.GetCurrentAnimatorStateInfo(0).IsName("run_run"))
  140.         {  
  141.             crownidle.GetComponent<SpriteRenderer>().enabled = false;
  142.             crownidle.GetComponent<Animator>().enabled = false;
  143.  
  144.             crownrun.GetComponent<SpriteRenderer>().enabled = true;
  145.             crownrun.GetComponent<Animator>().enabled = true;
  146.             animator.Play("run_run", 0, 0f);
  147.  
  148.             GetComponent<PlayerMovement>().runSpeed = 70f; 
  149.             GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().ghosts = 10;
  150.             GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().updateInterval = 0.09f;    
  151.            
  152.         }
  153.  
  154.         else if (animator.GetCurrentAnimatorStateInfo(0).IsName("idle_idle"))
  155.         {
  156.             crownrun.GetComponent<SpriteRenderer>().enabled = false;
  157.             crownrun.GetComponent<Animator>().enabled = false;
  158.  
  159.             crownidle.GetComponent<SpriteRenderer>().enabled = true;
  160.             crownidle.GetComponent<Animator>().enabled = true;
  161.             animator.Play("idle_idle", 0, 0f);
  162.  
  163.             GetComponent<PlayerMovement>().runSpeed = 70f; 
  164.             GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().ghosts = 10;
  165.             GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().updateInterval = 0.09f;
  166.  
  167.         }
  168.        
  169.         yield return new WaitForSeconds(5f);
  170.            
  171.         crownrun.GetComponent<SpriteRenderer>().enabled = false;
  172.         crownrun.GetComponent<Animator>().enabled = false;
  173.         animator.Play("run_run", 0, 0f);           
  174.        
  175.         GetComponent<PlayerMovement>().runSpeed = 50f;
  176.         GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().ghosts = 5;
  177.         GetComponent<ActionCode2D.Renderers.SpriteGhostTrailRenderer>().updateInterval = 0.03f;
  178.     }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement