Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class pohyb : MonoBehaviour {
- public float speedForce = 5f;
- public Vector2 jumpVector;
- public bool isGrounded;
- public Transform grounder;
- public float radiuss;
- public LayerMask ground;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKey (KeyCode.A)) {
- GetComponent<Rigidbody2D>().velocity = new Vector2 (-speedForce,GetComponent<Rigidbody2D>().velocity.y);
- transform.localScale = new Vector3 (-1,1,1);
- } else if (Input.GetKey (KeyCode.D)) {
- GetComponent<Rigidbody2D>().velocity = new Vector2 (speedForce,GetComponent<Rigidbody2D>().velocity.y);
- transform.localScale = new Vector3 (1,1,1);
- } else {
- GetComponent<Rigidbody2D>().velocity = new Vector2 (0,GetComponent<Rigidbody2D>().velocity.y);
- }
- isGrounded = Physics2D.OverlapCircle (grounder.transform.position, radiuss, ground);
- if (Input.GetKey (KeyCode.W) && isGrounded==true){
- GetComponent<Rigidbody2D>().AddForce (jumpVector, ForceMode2D.Force);
- }
- }
- void OnDrawGizmos(){
- Gizmos.color = Color.white;
- Gizmos.DrawWireSphere (grounder.transform.position, radiuss);
- }
- void OnTriggerEnter2d(Collider2D other){
- if (other.tag == "ostny") {
- Debug.Log("MRTEV");
- Application.LoadLevel(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement