Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class zeBRHAINS : MonoBehaviour {
  6.  
  7. // Use this for initialization
  8.  
  9. public float speed;
  10. public float jumpPower;
  11. public float maximumWallJump;
  12. public float maximumSpeed;
  13. public float health;
  14. public GameObject pain;
  15. private Rigidbody2D rb;
  16. private SpriteRenderer painRenderer;
  17.  
  18. void Start () {
  19. rb = GetComponent<Rigidbody2D>();
  20. painRenderer = pain.GetComponent<SpriteRenderer>();
  21.  
  22. }
  23.  
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. Color color = painRenderer.color;
  28. color.a = (100 - health) /100;
  29. painRenderer.color = color;
  30.  
  31. }
  32.  
  33. void FixedUpdate(){
  34. float moveHorizontal = Input.GetAxis("Horizontal");
  35. if (rb.velocity.x < maximumSpeed && rb.velocity.x > -maximumSpeed) {
  36. rb.AddForce (new Vector2 (moveHorizontal, 0) * speed);
  37. }
  38. }
  39.  
  40.  
  41. void OnCollisionStay2D(Collision2D collision){
  42.  
  43. if(collision.collider.name == "Tilemap" && Input.GetAxis("Vertical")>0 && rb.velocity.y<maximumWallJump){
  44. float highestY = collision.contacts [0].point.y;
  45. foreach (ContactPoint2D contact in collision.contacts) {
  46. if (contact.point.y > highestY) {
  47. highestY = contact.point.y;
  48. }
  49. }
  50. if (highestY < transform.position.y) {
  51. rb.AddForce (new Vector2 (0, 1) * jumpPower);
  52. } else {
  53. if (collision.contacts [0].point.x < transform.position.x) {
  54. rb.AddForce (new Vector2 (0.75f, 1f) * jumpPower);
  55. } else {
  56. rb.AddForce (new Vector2 (-0.75f, 1f) * jumpPower);
  57. }
  58. }
  59.  
  60. }
  61.  
  62. }
  63.  
  64. void OnTriggerStay2D(Collider2D collider){
  65. if (collider.name == "fire_0") {
  66. if (health == 0) {
  67. Destroy (gameObject);
  68. } else {
  69. health--;
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement