Advertisement
Nickanick12

Script 1.2

Feb 19th, 2022
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 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.     private SpriteRenderer sr;
  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.         sr = GetComponent<SpriteRenderer>();
  44.  
  45.         Health = GetComponent<Health>();
  46.  
  47.         scoreText = "Score: ";
  48.         timerText = "timer: ";
  49.         attackorClicking1 = GetComponent<Animator>();  
  50.     }
  51.  
  52.     // Update is called once per frame
  53.     void Update()
  54.     {
  55.  
  56.  
  57.         if (sr.sprite == GreyFrag && Input.GetMouseButtonDown(0) && coolDown <= 0)
  58.         {
  59.             Health.DamagePlayer(10);
  60.             Debug.Log("Conditon met");
  61.         }
  62.  
  63.         if (coolDown > 0)
  64.         {
  65.             coolDown -= Time.deltaTime;
  66.             timerText = "Cooldown: " + coolDown.ToString("F2");
  67.         }
  68.  
  69.         if ( Input.GetMouseButtonDown(0) && coolDown <= 0 )
  70.         {
  71.             score += 10;
  72.            
  73.             scoreText = "Score: " + score;
  74.             coolDown = alphaCoolDown;
  75.  
  76.             if (attackorClicking1 != null)
  77.             {
  78.                 attackorClicking1.SetTrigger("Attack");
  79.             }
  80.            
  81.         }
  82.        
  83.         if(SpriteCounter > 0)
  84.         {
  85.             SpriteCounter -= Time.deltaTime;
  86.         }
  87.  
  88.  
  89.        
  90.  
  91.  
  92.         if (SpriteCounter <= 0)
  93.         {
  94.             sr.sprite = GreyFrag;
  95.             SpriteCounter = 15f;
  96.             SpriteChangeCounter++;
  97.  
  98.             if(SpriteChangeCounter == 2)
  99.             {
  100.                 sr.sprite = RedFrag;
  101.                 SpriteChangeCounter = 0;
  102.             }
  103.  
  104.         }
  105.  
  106.  
  107.  
  108.     }
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement