Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MonsterMovement : MonoBehaviour {
- public Transform sightStart,sightEnd;
- bool collision=false;
- public bool needCollision=true;
- public static bool speedEnabled = false;
- public static float attackSpeed = 2;
- private Animator animator;
- public GameObject Adam;
- public float speed = 10f;
- public int count = 0;
- // Use this for initialization
- void Start () {
- animator = GetComponent<Animator>();
- }
- // Update is called once per frame
- void Update () {
- rigidbody2D.velocity = new Vector2 (transform.localScale.x, 0) * speed;
- animator.SetInteger ("State", 0);
- collision = Physics2D.Linecast
- (sightStart.position, sightEnd.position, 1 << LayerMask.NameToLayer ("Solid"));
- Debug.DrawLine (sightStart.position, sightEnd.position, Color.red);
- if(collision==needCollision )
- {
- rigidbody2D.transform.localScale = new Vector3((transform.localScale.x == 1) ? -1 : 1, 1, 1);
- }
- }
- void OnTriggerStay2D(Collider2D Enemy)
- {
- //Debug.Log ("Position: " + Enemy.rigidbody2D.position);
- Debug.Log ("Enemy.tag = " + Enemy.tag);
- Debug.Log ("GameObject " + Adam.name);
- if (Enemy.tag == "Player" && speedEnabled == false ) {
- count++;
- PlayerMovement.currentHealth = PlayerMovement.currentHealth - 40;
- PlayerMovement.changeAnimation.SetInteger ("State", 7);
- PlayerMovement.moving = false;
- Debug.Log ("Count => " + count);
- animator.Play ("Attack");
- Debug.Log ("this is adam");
- speedEnabled = true;
- } else {
- animator.SetInteger ("State", 0);
- }
- }
- public static void checkCreature()
- {
- //Debug.Log (Time.deltaTime);
- if(speedEnabled)
- {
- attackSpeed -= Time.deltaTime;
- if(attackSpeed <= 0)
- {
- Debug.Log ("checkCreature <= 0");
- speedEnabled = false;
- attackSpeed = 2;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement