Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class pohyb : MonoBehaviour {
  5.  
  6. public float speedForce = 5f;
  7. public Vector2 jumpVector;
  8. public bool isGrounded;
  9.  
  10. public Transform grounder;
  11. public float radiuss;
  12. public LayerMask ground;
  13.  
  14. // Use this for initialization
  15. void Start () {
  16.  
  17. }
  18.  
  19. // Update is called once per frame
  20. void Update () {
  21.  
  22. if (Input.GetKey (KeyCode.A)) {
  23. GetComponent<Rigidbody2D>().velocity = new Vector2 (-speedForce,GetComponent<Rigidbody2D>().velocity.y);
  24. transform.localScale = new Vector3 (-1,1,1);
  25. } else if (Input.GetKey (KeyCode.D)) {
  26. GetComponent<Rigidbody2D>().velocity = new Vector2 (speedForce,GetComponent<Rigidbody2D>().velocity.y);
  27. transform.localScale = new Vector3 (1,1,1);
  28. } else {
  29. GetComponent<Rigidbody2D>().velocity = new Vector2 (0,GetComponent<Rigidbody2D>().velocity.y);
  30. }
  31.  
  32. isGrounded = Physics2D.OverlapCircle (grounder.transform.position, radiuss, ground);
  33.  
  34. if (Input.GetKey (KeyCode.W) && isGrounded==true){
  35. GetComponent<Rigidbody2D>().AddForce (jumpVector, ForceMode2D.Force);
  36. }
  37.  
  38. }
  39.  
  40. void OnDrawGizmos(){
  41. Gizmos.color = Color.white;
  42. Gizmos.DrawWireSphere (grounder.transform.position, radiuss);
  43. }
  44.  
  45. void OnTriggerEnter2d(Collider2D other){
  46. if (other.tag == "ostny") {
  47. Debug.Log("MRTEV");
  48. Application.LoadLevel(0);
  49. }
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement