Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class takeDamage : MonoBehaviour {
  6.  
  7. public int health = 3;
  8. public bool hitJustTaker;
  9. public float imortallityTime;
  10.  
  11. private currentImortallityTime;
  12.  
  13. private Rigidbody2D rBody;
  14. private MoveScript MoveScript;
  15.  
  16. // Use this for initialization
  17. void Start () {
  18.  
  19. rBody = transform.GetComponent<Rigidbody2D>();
  20. MoveScript = transform.GetComponent<MoveScript>();
  21.  
  22. }
  23.  
  24. // Update is called once per frame
  25. void Update () {
  26.  
  27. currentImortallityTime -= Time.deltaTime;
  28.  
  29. if (MoveScript)
  30. {
  31. if (MoveScript.invincible || currentImortallityTime > 0)
  32. {
  33. Physics2D.IgnoreLayerCollision(10, 9, true);
  34. }
  35. else
  36. {
  37. Physics2D.IgnoreLayerCollision(10, 9, false);
  38. }
  39. }
  40.  
  41. }
  42.  
  43. void changeHealth(int value)
  44. {
  45. health += value;
  46. }
  47.  
  48. void die()
  49. {
  50. Destroy(gameObject);
  51. }
  52.  
  53. void push(Vector2 direction)
  54. {
  55. rBody.AddForce(direction, ForceMode2D.Impulse);
  56. }
  57.  
  58. void OnCollisionEnter2D(Collision collisionData)
  59. {
  60. if(Physics2D.IsTouchingLayers(transform.GetComponent<Collider2D>(), 10))
  61. {
  62.  
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement