Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class zeBRHAINS : MonoBehaviour {
- // Use this for initialization
- public float speed;
- public float jumpPower;
- public float maximumWallJump;
- public float maximumSpeed;
- public float health;
- public GameObject pain;
- private Rigidbody2D rb;
- private SpriteRenderer painRenderer;
- void Start () {
- rb = GetComponent<Rigidbody2D>();
- painRenderer = pain.GetComponent<SpriteRenderer>();
- }
- // Update is called once per frame
- void Update()
- {
- Color color = painRenderer.color;
- color.a = (100 - health) /100;
- painRenderer.color = color;
- }
- void FixedUpdate(){
- float moveHorizontal = Input.GetAxis("Horizontal");
- if (rb.velocity.x < maximumSpeed && rb.velocity.x > -maximumSpeed) {
- rb.AddForce (new Vector2 (moveHorizontal, 0) * speed);
- }
- }
- void OnCollisionStay2D(Collision2D collision){
- if(collision.collider.name == "Tilemap" && Input.GetAxis("Vertical")>0 && rb.velocity.y<maximumWallJump){
- float highestY = collision.contacts [0].point.y;
- foreach (ContactPoint2D contact in collision.contacts) {
- if (contact.point.y > highestY) {
- highestY = contact.point.y;
- }
- }
- if (highestY < transform.position.y) {
- rb.AddForce (new Vector2 (0, 1) * jumpPower);
- } else {
- if (collision.contacts [0].point.x < transform.position.x) {
- rb.AddForce (new Vector2 (0.75f, 1f) * jumpPower);
- } else {
- rb.AddForce (new Vector2 (-0.75f, 1f) * jumpPower);
- }
- }
- }
- }
- void OnTriggerStay2D(Collider2D collider){
- if (collider.name == "fire_0") {
- if (health == 0) {
- Destroy (gameObject);
- } else {
- health--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement