Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class AttackScript : MonoBehaviour
- {
- private GUIStyle scoreStyle = new GUIStyle();
- private GUIStyle timerStyle = new GUIStyle();
- public string scoreText;
- public string timerText;
- Health Health;
- public Sprite emptySprite;
- public Sprite GreyFrag;
- public Sprite RedFrag;
- public float SpriteCounter = 15f;
- public int SpriteChangeCounter = 0;
- public int score = 0;
- public const float alphaCoolDown = 1.5f;
- public float coolDown = alphaCoolDown;
- void OnGUI()
- {
- // Make a text field that modifies stringToEdit.
- scoreStyle.fontSize = 30;
- timerStyle.fontSize = 15;
- GUI.Label(new Rect(10, 10, 400, 20), scoreText, scoreStyle);
- GUI.Label(new Rect(10, 50, 400, 20), timerText, timerStyle);
- }
- Animator attackorClicking1;
- // Start is called before the first frame update
- void Start()
- {
- this.gameObject.GetComponent<SpriteRenderer>().sprite = emptySprite;
- Health = GetComponent<Health>();
- scoreText = "Score: ";
- timerText = "timer: ";
- attackorClicking1 = GetComponent<Animator>();
- }
- // Update is called once per frame
- void Update()
- {
- if (coolDown > 0)
- {
- coolDown -= Time.deltaTime;
- timerText = "Cooldown: " + coolDown.ToString("F2");
- }
- if ( Input.GetMouseButtonDown(0) && coolDown <= 0 )
- {
- score += 10;
- scoreText = "Score: " + score;
- coolDown = alphaCoolDown;
- if (attackorClicking1 != null)
- {
- attackorClicking1.SetTrigger("Attack");
- }
- }
- if(SpriteCounter > 0)
- {
- SpriteCounter -= Time.deltaTime;
- }
- if(emptySprite == GreyFrag && Input.GetMouseButtonDown(0) && coolDown <= 0)
- {
- Health.DamagePlayer(10);
- Debug.LogError("Conditions not met.");
- }
- if (SpriteCounter <= 0)
- {
- emptySprite = GreyFrag;
- SpriteCounter = 15f;
- SpriteChangeCounter++;
- if(SpriteChangeCounter == 2)
- {
- emptySprite = RedFrag;
- SpriteChangeCounter = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement