Advertisement
CarlosWGama

Untitled

Aug 30th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Ghost : MonoBehaviour {
  5.  
  6.     public float intervaloAtaque;
  7.     private float contagemIntervalo;
  8.     private bool atacou;
  9.     public float distanciaAtaque;
  10.  
  11.     public GameObject ataque;
  12.     public GameObject player;
  13.  
  14.     private Animator animator;
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18.         animator = gameObject.transform.GetComponent<Animator> ();
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update () {
  23.         var distancia = (player.transform.position.x - transform.position.x);
  24.         if (distancia > 0) {
  25.             transform.eulerAngles = new Vector2(0, 0);
  26.         } else {
  27.             transform.eulerAngles = new Vector2(0, 180);
  28.         }
  29.  
  30.         if (!atacou && Mathf.Abs(distancia) <= distanciaAtaque) {
  31.             animator.SetTrigger("atacou");
  32.             Invoke("Ataque", 1.5f); //CHAMA O METODO ATAQUE APOS 1,5 SEGUNDOS
  33.             atacou = true;
  34.         }
  35.         if (atacou) {
  36.             contagemIntervalo += Time.deltaTime;
  37.             if (contagemIntervalo >= intervaloAtaque) {
  38.                 atacou = false;
  39.                 contagemIntervalo = 0;
  40.             }
  41.         }
  42.     }
  43.  
  44.     //ESSE É O METODO CHAMADO
  45.     void Ataque() {
  46.         Instantiate(ataque, transform.position, transform.rotation);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement