Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MonsterMovement : MonoBehaviour {
  5. public Transform sightStart,sightEnd;
  6. bool collision=false;
  7. public bool needCollision=true;
  8.  
  9. public static bool speedEnabled = false;
  10. public static float attackSpeed = 2;
  11.  
  12. private Animator animator;
  13. public GameObject Adam;
  14. public float speed = 10f;
  15. public int count = 0;
  16. // Use this for initialization
  17. void Start () {
  18. animator = GetComponent<Animator>();
  19. }
  20.  
  21.  
  22. // Update is called once per frame
  23. void Update () {
  24. rigidbody2D.velocity = new Vector2 (transform.localScale.x, 0) * speed;
  25. animator.SetInteger ("State", 0);
  26.  
  27. collision = Physics2D.Linecast
  28. (sightStart.position, sightEnd.position, 1 << LayerMask.NameToLayer ("Solid"));
  29. Debug.DrawLine (sightStart.position, sightEnd.position, Color.red);
  30.  
  31.  
  32. if(collision==needCollision )
  33. {
  34.  
  35. rigidbody2D.transform.localScale = new Vector3((transform.localScale.x == 1) ? -1 : 1, 1, 1);
  36.  
  37. }
  38. }
  39.  
  40. void OnTriggerStay2D(Collider2D Enemy)
  41. {
  42. //Debug.Log ("Position: " + Enemy.rigidbody2D.position);
  43. Debug.Log ("Enemy.tag = " + Enemy.tag);
  44. Debug.Log ("GameObject " + Adam.name);
  45. if (Enemy.tag == "Player" && speedEnabled == false ) {
  46. count++;
  47. PlayerMovement.currentHealth = PlayerMovement.currentHealth - 40;
  48. PlayerMovement.changeAnimation.SetInteger ("State", 7);
  49. PlayerMovement.moving = false;
  50. Debug.Log ("Count => " + count);
  51. animator.Play ("Attack");
  52. Debug.Log ("this is adam");
  53. speedEnabled = true;
  54. } else {
  55. animator.SetInteger ("State", 0);
  56. }
  57. }
  58.  
  59.  
  60. public static void checkCreature()
  61. {
  62. //Debug.Log (Time.deltaTime);
  63. if(speedEnabled)
  64. {
  65. attackSpeed -= Time.deltaTime;
  66. if(attackSpeed <= 0)
  67. {
  68. Debug.Log ("checkCreature <= 0");
  69. speedEnabled = false;
  70. attackSpeed = 2;
  71.  
  72. }
  73. }
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement