Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerController : MonoBehaviour {
- public float jumpHeight;
- private bool jumpClicked;
- public Transform groundCheck;
- public LayerMask whatIsGround;
- public float groundCheckRadius;
- private bool grounded;
- private AudioSource audioSource;
- public AudioClip jumpSound;
- // Use this for initialization
- void Start ()
- {
- audioSource = GetComponent<AudioSource>();
- }
- // Update is called once per frame
- void Update ()
- {
- jumpBehavior();
- SlideBehavior();
- }
- void FixedUpdate()
- {
- grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
- }
- private void jumpBehavior()
- {
- if (grounded)
- {
- audioSource.Play();
- if (Input.GetKeyDown(KeyCode.Space) || jumpClicked && grounded)
- {
- AudioSource.PlayClipAtPoint(jumpSound, transform.position);
- var accessAnimation = GetComponent<Animator>();
- var accessRigidBody = GetComponent<Rigidbody2D>();
- accessRigidBody.velocity = new Vector2(transform.position.x, jumpHeight);
- accessAnimation.SetTrigger("Jump");
- accessAnimation.SetTrigger("Land");
- jumpClicked = false;
- audioSource.Stop();
- }
- }
- }
- public void clickToJump()
- {
- jumpClicked = true;
- }
- void SlideBehavior()
- {
- if (Input.GetKeyDown(KeyCode.S))
- {
- var accessAnimation = GetComponent<Animator>();
- accessAnimation.SetTrigger("Slide");
- accessAnimation.SetTrigger("Land");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement