Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Help with script

$
0
0
![alt text][1] [1]: /storage/temp/69607-screen-shot-2016-05-07-at-150451.png ---------------------------------------------------------------------------------------------------------------------------------------------- private Animator myAnimator; [SerializeField] private float movementSpeed; private bool facingRight; [SerializeField] private Transform[] groundPoints; [SerializeField] private float groundRadius; [SerializeField] private LayerMask whatIsGround; [SerializeField] private bool airControl; [SerializeField] private float jumpForce; public Rigidbody2D MyRigibody { get; set; } public bool Attack { get; set; } public bool Jump { get; set; } public bool OnGround { get; set; } // Use this for initialization void Start () { facingRight = true; MyRigibody = GetComponent (); myAnimator = GetComponent (); } void Update() { HandleInput(); } // Update is called once per frame void FixedUpdate() { float horizontal = Input.GetAxis ("Horizontal"); OnGround = IsGrounded(); HandleMovement(horizontal); Flip(horizontal); HandleLayers (); } private void HandleMovement (float horizontal) { if (MyRigibody.velocity.y < 0) { myAnimator.SetBool ("land", true); } if (!Attack && (OnGround || airControl)) { MyRigibody.velocity = new Vector2 (horizontal * movementSpeed, myAnimator.velocity.y); } if (Jump && MyRigibody.velocity.y == 0) { MyRigibody.AddForce(new Vector2(0, jumpForce)); } myAnimator.SetFloat ("speed", Mathf.Abs (horizontal)); } private void HandleInput() { if (Input.GetKeyDown(KeyCode.Space)) { } if (Input.GetKeyDown(KeyCode.LeftShift)) { } } private void Flip (float horizontal) { if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight) { facingRight = !facingRight; Vector3 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale; } } private bool IsGrounded() { if (MyRigibody.velocity.y <= 0) { foreach (Transform point in groundPoints) { Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject) return true; } } } } return false; } private void HandleLayers() { if (!OnGround) { myAnimator.SetLayerWeight (1, 1); } else { myAnimator.SetLayerWeight (1, 0); } } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>