Advertisement
Nickanick12

Script 1

Feb 19th, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class AttackScript : MonoBehaviour
  7. {
  8.  
  9.    
  10.  
  11.     private GUIStyle scoreStyle = new GUIStyle();
  12.     private GUIStyle timerStyle = new GUIStyle();
  13.     public string scoreText;
  14.     public string timerText;
  15.  
  16.     Health HealthBar;
  17.    
  18.     public Sprite GreyFrag;
  19.     public Sprite RedFrag;
  20.     public float SpriteCounter = 15f;
  21.     public int SpriteChangeCounter = 0;
  22.  
  23.  
  24.     public int score = 0;
  25.     public const float alphaCoolDown = 1.5f;
  26.     public float coolDown = alphaCoolDown;
  27.     void OnGUI()
  28.     {
  29.         // Make a text field that modifies stringToEdit.
  30.         scoreStyle.fontSize = 30;
  31.         timerStyle.fontSize = 15;
  32.         GUI.Label(new Rect(10, 10, 400, 20), scoreText, scoreStyle);
  33.         GUI.Label(new Rect(10, 50, 400, 20), timerText, timerStyle);
  34.     }
  35.  
  36.  
  37.         Animator attackorClicking1;
  38.  
  39.     // Start is called before the first frame update
  40.     void Start()
  41.     {
  42.        
  43.         HealthBar = GetComponent<Health>();
  44.  
  45.         scoreText = "Score: ";
  46.         timerText = "timer: ";
  47.         attackorClicking1 = GetComponent<Animator>();  
  48.     }
  49.  
  50.     // Update is called once per frame
  51.     void Update()
  52.     {
  53.  
  54.         if (coolDown > 0)
  55.         {
  56.             coolDown -= Time.deltaTime;
  57.             timerText = "Cooldown: " + coolDown.ToString("F2");
  58.         }
  59.  
  60.         if ( Input.GetMouseButtonDown(0) && coolDown <= 0 )
  61.         {
  62.             score += 10;
  63.             attackorClicking1.SetTrigger("Attack");
  64.             scoreText = "Score: " + score;
  65.             coolDown = alphaCoolDown;
  66.         }
  67.        
  68.         if(SpriteCounter > 0)
  69.         {
  70.             SpriteCounter -= Time.deltaTime;
  71.         }
  72.  
  73.  
  74.         if(this.gameObject.GetComponent<SpriteRenderer>().sprite == GreyFrag && Input.GetMouseButtonDown(0) && coolDown <= 0)
  75.         {
  76.             HealthBar.DamagePlayer(10);
  77.         }
  78.  
  79.  
  80.         if (SpriteCounter <= 0)
  81.         {
  82.             this.gameObject.GetComponent<SpriteRenderer>().sprite = GreyFrag;
  83.             SpriteCounter = 15f;
  84.             SpriteChangeCounter++;
  85.  
  86.             if(SpriteChangeCounter == 2)
  87.             {
  88.                 this.gameObject.GetComponent<SpriteRenderer>().sprite = RedFrag;
  89.                 SpriteChangeCounter = 0;
  90.             }
  91.  
  92.         }
  93.  
  94.  
  95.  
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement