Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerMovement : MonoBehaviour {
- //movimentando
- public float walkSpeed = 10f;
- //pulando
- public float alturaPulo = 200f;
- private int numPulos = 0;
- private bool pulouDoChao = false;
- //animaçao
- // Animator anim;
- // float jumpTime, jumpDelay = .5f;
- bool jumped;
- //variaveis de colisao
- public Transform baixo1, baixo2;
- bool baixo = false;
- public Transform cima1, cima2;
- bool cima = false;
- public Player2 p2;
- //verificando objetos ao redor [chao e outros]
- public bool grounded_p1 = false;
- bool obstacle = false;
- // Use this for initialization
- void Start ()
- {
- //anim = GetComponent<Animator> ();
- }
- void Update ()
- {
- //movimentacao
- float move = Input.GetAxis ("Horizontal_P1");
- rigidbody2D.velocity = new Vector2 (move * walkSpeed, rigidbody2D.velocity.y);
- // print (rigidbody2D.transform.rotation.z);
- isGrounded ();
- overHead ();
- //pulo
- if (Input.GetKeyDown (KeyCode.W))
- {
- if (obstacle == true && grounded_p1 == false)
- {
- //print ("sem pulos");
- }
- if (numPulos == 0 && grounded_p1 == true) //primeiro pulo
- {
- pulo ();
- numPulos = 1;
- pulouDoChao = true;
- }
- }
- }
- void FixedUpdate ()
- {
- }
- void pulo()
- {
- rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0);
- rigidbody2D.AddForce(new Vector2(0f, alturaPulo));
- }
- void RayCasting(string layer)
- {
- Debug.DrawLine (baixo1.position, baixo2.position, Color.green);
- baixo = Physics2D.Linecast (baixo1.position, baixo2.position, 1 << LayerMask.NameToLayer(layer));
- Debug.DrawLine (cima1.position, cima2.position, Color.green);
- cima = Physics2D.Linecast (cima1.position, cima2.position, 1 << LayerMask.NameToLayer(layer));
- }
- void isGrounded()
- {
- RayCasting ("Ground");
- if (baixo == true)
- {
- grounded_p1 = true; numPulos = 0;
- }
- else
- {
- grounded_p1 = false;
- }
- }
- void overHead ()
- {
- RayCasting ("Player");
- if (cima == true)
- {
- print ("cabeça P2");
- }
- if (baixo == true)
- {
- rigidbody2D.AddForce(new Vector2(0f, 700));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement