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 HealthBar;
- 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()
- {
- HealthBar = 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;
- attackorClicking1.SetTrigger("Attack");
- scoreText = "Score: " + score;
- coolDown = alphaCoolDown;
- }
- if(SpriteCounter > 0)
- {
- SpriteCounter -= Time.deltaTime;
- }
- if(this.gameObject.GetComponent<SpriteRenderer>().sprite == GreyFrag && Input.GetMouseButtonDown(0) && coolDown <= 0)
- {
- HealthBar.DamagePlayer(10);
- }
- if (SpriteCounter <= 0)
- {
- this.gameObject.GetComponent<SpriteRenderer>().sprite = GreyFrag;
- SpriteCounter = 15f;
- SpriteChangeCounter++;
- if(SpriteChangeCounter == 2)
- {
- this.gameObject.GetComponent<SpriteRenderer>().sprite = RedFrag;
- SpriteChangeCounter = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement