Advertisement
Nickanick12

Script 1.1

Feb 19th, 2022
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 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 Health;
  17.  
  18.     public Sprite emptySprite;
  19.     public Sprite GreyFrag;
  20.     public Sprite RedFrag;
  21.     public float SpriteCounter = 15f;
  22.     public int SpriteChangeCounter = 0;
  23.  
  24.  
  25.     public int score = 0;
  26.     public const float alphaCoolDown = 1.5f;
  27.     public float coolDown = alphaCoolDown;
  28.     void OnGUI()
  29.     {
  30.         // Make a text field that modifies stringToEdit.
  31.         scoreStyle.fontSize = 30;
  32.         timerStyle.fontSize = 15;
  33.         GUI.Label(new Rect(10, 10, 400, 20), scoreText, scoreStyle);
  34.         GUI.Label(new Rect(10, 50, 400, 20), timerText, timerStyle);
  35.     }
  36.  
  37.  
  38.         Animator attackorClicking1;
  39.  
  40.     // Start is called before the first frame update
  41.     void Start()
  42.     {
  43.  
  44.         this.gameObject.GetComponent<SpriteRenderer>().sprite = emptySprite;
  45.  
  46.         Health = GetComponent<Health>();
  47.  
  48.         scoreText = "Score: ";
  49.         timerText = "timer: ";
  50.         attackorClicking1 = GetComponent<Animator>();  
  51.     }
  52.  
  53.     // Update is called once per frame
  54.     void Update()
  55.     {
  56.  
  57.         if (coolDown > 0)
  58.         {
  59.             coolDown -= Time.deltaTime;
  60.             timerText = "Cooldown: " + coolDown.ToString("F2");
  61.         }
  62.  
  63.         if ( Input.GetMouseButtonDown(0) && coolDown <= 0 )
  64.         {
  65.             score += 10;
  66.            
  67.             scoreText = "Score: " + score;
  68.             coolDown = alphaCoolDown;
  69.  
  70.             if (attackorClicking1 != null)
  71.             {
  72.                 attackorClicking1.SetTrigger("Attack");
  73.             }
  74.            
  75.         }
  76.        
  77.         if(SpriteCounter > 0)
  78.         {
  79.             SpriteCounter -= Time.deltaTime;
  80.         }
  81.  
  82.  
  83.         if(emptySprite == GreyFrag && Input.GetMouseButtonDown(0) && coolDown <= 0)
  84.         {
  85.             Health.DamagePlayer(10);
  86.              Debug.LogError("Conditions not met.");
  87.         }
  88.        
  89.  
  90.  
  91.         if (SpriteCounter <= 0)
  92.         {
  93.             emptySprite = GreyFrag;
  94.             SpriteCounter = 15f;
  95.             SpriteChangeCounter++;
  96.  
  97.             if(SpriteChangeCounter == 2)
  98.             {
  99.                 emptySprite = RedFrag;
  100.                 SpriteChangeCounter = 0;
  101.             }
  102.  
  103.         }
  104.  
  105.  
  106.  
  107.     }
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement