Advertisement
Guest User

Movemente_Bear

a guest
Oct 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class UrsoMov : MonoBehaviour {
  6.     float moveX, moveY;
  7.     public float speed;
  8.     public GameObject atkU;
  9.     public GameObject gunnerU;
  10.     private int hp = 0;
  11.     public float forca;
  12.     bool estouNoChao;
  13.     GameObject UltimaBala;
  14.     private float speedBullet = 10;
  15.     // Use this for initialization
  16.     void Start () {
  17.        
  18.     }
  19.    
  20.     // Update is called once per frame
  21.     void Update () {
  22.        
  23.         if (Input.GetKeyDown (KeyCode.UpArrow)) {
  24.             if (estouNoChao == true) {
  25.                 GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0f, forca), ForceMode2D.Impulse);
  26.                 GetComponent<Animator> ().SetBool ("noPulando", true);
  27.                 transform.GetChild(1).gameObject.layer = 11;
  28.                 this.gameObject.layer = 11;
  29.             }
  30.  
  31.         }
  32.         if (GetComponent<Rigidbody2D> ().velocity.y < 0) {
  33.             transform.GetChild(1).gameObject.layer = 10;
  34.             this.gameObject.layer = 10;
  35.         }
  36.         if (Input.GetKey (KeyCode.DownArrow)) {
  37.             if (estouNoChao == true) {
  38.                 GetComponent<Animator> ().SetBool ("noAgachando", true);           
  39.             }
  40.         }
  41.             if (Input.GetKeyUp (KeyCode.DownArrow)) {
  42.                 GetComponent<Animator> ().SetBool ("noLevantando", false); 
  43.                 GetComponent<Animator> ().SetBool ("noAgachando", false);
  44.             }
  45.  
  46.  
  47.  
  48.         moveX = Input.GetAxis ("Horizontal");
  49.         if (moveX != 0) {
  50.             GetComponent<Animator> ().SetBool ("noAndando", true); 
  51.             if (moveX < 0) {
  52.                 GetComponent<SpriteRenderer> ().flipX = true;
  53.                 transform.GetChild (0).transform.localPosition = new Vector2(-2.41f,0.48f);
  54.  
  55.             } else {
  56.                 GetComponent<SpriteRenderer> ().flipX = false;
  57.                 transform.GetChild (0).transform.localPosition = new Vector2(2.41f,0.48f);
  58.             }
  59.  
  60.         }
  61.         //moveY = Input.GetAxis ("Vertical");
  62.         transform.Translate (moveX * Time.deltaTime * speed, moveY * Time.deltaTime * speed, 0f);
  63.         if (Input.GetKeyDown (KeyCode.Space)) {
  64.             UltimaBala = Instantiate (atkU, gunnerU.transform.position, Quaternion.identity);
  65.  
  66.             if (GetComponent<SpriteRenderer> ().flipX == true) {
  67.                 UltimaBala.GetComponent<BulletU> ().velocidade *= -1;  
  68.             }
  69.  
  70.         }
  71.     }
  72.     void OnCollisionEnter2D (Collision2D collision){
  73.         if (collision.gameObject.CompareTag ("Bee")) {
  74.             hp++;
  75.         }
  76.         if (hp >= 3) {
  77.             Destroy (this.gameObject);
  78.         }
  79.         if (collision.gameObject.CompareTag("chao"))
  80.         {
  81.                 estouNoChao = true;        
  82.         }
  83. }
  84.     void OnCollisionExit2D (Collision2D collision){
  85.         if (collision.gameObject.CompareTag ("chao")) {
  86.             estouNoChao = false;
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement