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 UrsoMov : MonoBehaviour {
- float moveX, moveY;
- public float speed;
- public GameObject atkU;
- public GameObject gunnerU;
- private int hp = 0;
- public float forca;
- bool estouNoChao;
- GameObject UltimaBala;
- private float speedBullet = 10;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown (KeyCode.UpArrow)) {
- if (estouNoChao == true) {
- GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0f, forca), ForceMode2D.Impulse);
- GetComponent<Animator> ().SetBool ("noPulando", true);
- transform.GetChild(1).gameObject.layer = 11;
- this.gameObject.layer = 11;
- }
- }
- if (GetComponent<Rigidbody2D> ().velocity.y < 0) {
- transform.GetChild(1).gameObject.layer = 10;
- this.gameObject.layer = 10;
- }
- if (Input.GetKey (KeyCode.DownArrow)) {
- if (estouNoChao == true) {
- GetComponent<Animator> ().SetBool ("noAgachando", true);
- }
- }
- if (Input.GetKeyUp (KeyCode.DownArrow)) {
- GetComponent<Animator> ().SetBool ("noLevantando", false);
- GetComponent<Animator> ().SetBool ("noAgachando", false);
- }
- moveX = Input.GetAxis ("Horizontal");
- if (moveX != 0) {
- GetComponent<Animator> ().SetBool ("noAndando", true);
- if (moveX < 0) {
- GetComponent<SpriteRenderer> ().flipX = true;
- transform.GetChild (0).transform.localPosition = new Vector2(-2.41f,0.48f);
- } else {
- GetComponent<SpriteRenderer> ().flipX = false;
- transform.GetChild (0).transform.localPosition = new Vector2(2.41f,0.48f);
- }
- }
- //moveY = Input.GetAxis ("Vertical");
- transform.Translate (moveX * Time.deltaTime * speed, moveY * Time.deltaTime * speed, 0f);
- if (Input.GetKeyDown (KeyCode.Space)) {
- UltimaBala = Instantiate (atkU, gunnerU.transform.position, Quaternion.identity);
- if (GetComponent<SpriteRenderer> ().flipX == true) {
- UltimaBala.GetComponent<BulletU> ().velocidade *= -1;
- }
- }
- }
- void OnCollisionEnter2D (Collision2D collision){
- if (collision.gameObject.CompareTag ("Bee")) {
- hp++;
- }
- if (hp >= 3) {
- Destroy (this.gameObject);
- }
- if (collision.gameObject.CompareTag("chao"))
- {
- estouNoChao = true;
- }
- }
- void OnCollisionExit2D (Collision2D collision){
- if (collision.gameObject.CompareTag ("chao")) {
- estouNoChao = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement